javascript - 如果字段具有默认值,如何使用验证插件对输入字段进行必需
问题描述
我有一个表格,如果在其中选择或填写了任何其他字段,我正在使用验证插件。
我想要的是,如果输入字段有一个默认值,比如给定value="0.00"
它不应该使其他输入字段成为必需,只有在手动填写时才成为必需。
<div class="col-md-3">
<div class="form-group">
<label>From Recognition Score</label>
<input type="text" name="from_individual_recognition_score_3rd" class="form-control m2 validate[condRequired[recognize_1,recognize_3,recognize_4],min[1]]" id="recognize_2" maxlength="5" value='0.00'>
</div>
</div>
感谢和问候
解决方案
仅在手动填写时才需要
这没有任何意义。required
如果已经填满了东西,你怎么能创建一个字段?只能制作空字段required
。一旦它们包含一个值,它们就不再是“必需的”,因为required
验证规则已完全满足。
使用该placeholder
属性,因为这就是它的用途;向用户显示默认值或示例值。
Showing the default value using placeholder attribute:
<input type="text" placeholder="0.00" name="from_individual_recognition_score_3rd" />
否则,也许您可以编写一个对您的项目更有意义的自定义规则/方法。由于您在 OP 中显示的代码非常少,因此无法知道在这里可以使用什么。
推荐阅读
- python - How to dynamically delete DAGs?
- node.js - Rewriting a NodeJS Website using Oracle APEX
- .htaccess - Allow 3 ip's, redirect for other ip's and redirect to mobile site
- c - 链接库还是将它们带到 test.c 代码所在的本地目录更好?
- reactjs - 反应和对象 - 类型错误:无法读取未定义的属性“地图”
- c# - Azure 函数 QueueTrigger 和 int 消息
- java - Java versions don't match between command prompt and STS
- java - Opentelemetry java Automatic Instrumentation with zipkin exporter 选项正在使用 OtlpGrpcSpanExporter
- r - 在两个变量的比例之间创建一个图
- python - 在 python 中安装 arpreq 时如何修复错误?