错误消息重复多次引导和jQuery验证表单
error message repeat multiple time - bootstrap and jQuery validation form
对于我的注册表单,我使用bootstrap 3和jQuery Validation插件。除了每次用户单击字段时都会重复出现错误消息之外,其他一切都很好。我检查了一些工作示例,没有发现与我的代码有任何不同。我还试图删除()或隐藏()错误消息,但仍然存在。有什么解决的建议吗?
<form accept-charset="UTF-8" method="post" action="form.php" class="form-inline" novalidate="novalidate">
<div class="row col-md-10">
<label for="name" class="control-label">Full name*</label>
<input type="text" class="form-control" id="name" name="name">
<label for="email" class="control-label">E-mail*</label>
<input type="email" class="form-control" id="email" name="email" placeholder="e.g. yourname@work.com, yourname@university.com, ...">
<label for="city" class="control-label">City*</label>
<input type="text" class="form-control" id="country" name="country" data-validation="country" data-toggle="tooltip" data-placement="right" title="" data-original-title="Why we need your city? We aim to match people on a regional basis. Although this is done for ensuring convenient times as most contact is usually via phone or video." name="city">
<label for="zipcode"> Zip code </label>
<input type="text" class="ignore form-control zipcode" name="zipcode">
</div>
<div class="row col-md-10">
<label for="currently_employed" class="control-label currently_employed"> Are you in current employment?* </label>
<ul class="options">
<li>
<input type="radio" class="form-control" id="user_currently_employed_true" name="currently_employed" value="true" />
<label for="currently_employed_true" class="control-label"> Yes </label>
</li>
<li>
<input type="radio" class="form-control" id="user_currently_employed_false" name="currently_employed" value="false" />
<label for="currently_employed_false" class="control-label"> No </label>
</li>
</ul>
<div class="clear"></div>
<label for="company" class="control-label"> Your Company/University* </label>
<input type="text" class="form-control" name="company"/>
</div>
[....]
</form>
验证:
<script src="lib/jquery.validate.min.js"></script>
<script src="lib/jquery.form.js"></script>
<script src="lib/jquery.mockjax.js"></script>
<script src="lib/additional-methods.min.js"></script>
<script>
$('#country').tooltip();
$('form').validate({
ignore: '.ignore',
rules: {
name: {
minlength: 2,
required: true
},
email: {
required: true,
email: true
},
messages: {
name: "Please specify your name",
email: {
required: "We need your email address to contact you",
email: "Your email address must be in the format of name@domain.com"
}
}
},
errorPlacement: function(error, element) {
error.insertAfter('#wrap-error span');
},
highlight: function(element) {
$(element).closest('.form-inline').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-inline').removeClass('has-error');
}
});
</script>
</body>
</html>
我终于弄清楚问题出在哪里了。它只是请求包含#wrap错误,即在表单元素内部附加错误消息的错误。
我也有类似的错误,但这是因为页面中有多个元素与我的错误element
选择器匹配。换句话说,对于下面的代码片段,我的页面上有不止一件事与element
匹配
error.insertAfter(element);
相关文章:
- 如何使用jQuery验证引擎验证组
- jQuery:使用“jQuery验证”后无法提交表单's远程验证
- 一个jquery验证器方法,它不接受纯数字或纯特殊字符,但接受上面是否有字母
- jQuery验证器添加方法未定义
- jQuery验证插件submitHandler Ajax
- 使用jquery验证函数不适用于select元素
- 动态jQuery验证
- 如果使用jQuery验证器插件找到单选按钮,则将不同的addMethod应用于字段
- 使用jquery验证信用卡
- 未使用jQuery验证器选中Css样式复选框时
- 自定义jquery验证器
- Jquery验证消息更改(自定义消息集)
- 时间日志的javascript/jquery验证(5小时3米)
- jQuery 验证正在复制 else 语句 |验证完成后,不会打印值
- 将动态验证文本添加到自定义jQuery验证规则中
- Jquery 验证插件 - 字段仍然产生错误
- 验证字段名称 添加 与 使用 jquery 验证
- JQUERY 验证 - 序列化选择和复选框
- jQuery 验证 - 调用某些元素的 .valid() 方法不会清除错误
- 带有jquery验证问题的php表单