我正在使用非常好的 bassistance 验证插件来满足我所有的表单验证需求: http ://bassistance.de/jquery-plugins/jquery-plugin-validation/
我遇到的一个问题:即使用户还没有完成一个字段,错误消息也会立即出现。因此:在用户完成输入之前,会出现无效的电子邮件。
在此处的文档中,一种解决方案是将选项设置onkeyup
为false
导致错误消息仅出现 onblur。
但是,在我的设置中,我遇到了两个额外的问题(上面的解决方案没有解决)
- 提交无效表单后,更正错误消息时不会清除它们
- 使用浏览器自动填充功能时,自动填写的字段会一直标记为错误。
所以,我最初的问题是:我怎样才能让 Bassistance 验证仅在第一次提交后触发,并且从那里开始使用它的默认设置?
这是我的代码:
if($('#contact_form').length) {
$("#contact_form").validate({
rules: {
first_name: {
required: true
},
last_name: {
required: true
},
message: {
required: true
},
telephone: {
required: true
},
email: {
required: true,
email: true
},
email_again: {
required: true,
email: true,
equalTo: "#email"
},
norobot: {
required:true,
minlength:4,
maxlength:4,
number:true
}
}
});
}
请在此处找到完整的 JavaScript:http: //lad.chocolata.be/js/main.js
onkeyup
这是一个设置为错误的工作示例:http false
:
//lad.chocolata.be/nl/contact
提交带有一些无效字段的表单后,错误消息在更正时不会清除。
我错过了什么?