从字面上看,我已经使用了这个插件数百次,从来没有遇到过这样的问题.. 现在,当提交表单(字段为空)时,错误标签会正确显示.. 然而,当您填写一个字段或两个正确,这些字段的错误不会消失..如果您重新提交表单,它会提交..即使字段保持为空..并且未经验证。
我正在运行 jQuery v1.8.2 和 jQuery Validate v1.11.0 该站点在 Twitter 引导程序上运行,因此插件代码末尾的突出显示、成功和错误放置功能。
我可以提供开发人员的链接。环境,如果你给我发消息并有可能的修复,但想查看实时代码(这个应用程序尚未启动,我刚刚被雇用来清理一些东西,..因此处理这样的问题:[ )
非常感谢任何输入,谢谢!
这是JS:
$.validator.setDefaults({
submitHandler: function() {
form.submit();
}
});
$('#register').validate({
rules: {
name: {
minlength: 2,
required: true
},
lname: {
minlength: 2,
required: true
},
username: {
minlength: 2,
required: true,
remote: {
url: '/setup/verify_username/',
cache: false
}
},
email: {
required: true,
email: true,
remote: {
url: '/setup/verify_email/',
cache: false
}
},
password: {
required: true,
alphaNumeric: true,
minlength: 5,
maxlength: 250
},
password2: {
required: true,
alphaNumeric: true,
minlength: 5,
maxlength: 250,
equalTo: '#password'
},
postal_code: {
required: true,
minlength: 5
},
timezones: {
required: true
},
mp: {
minlength: 10,
required: true
},
gender: {
required: true
},
dob: {
required: true,
date: true
}
},
messages: {
name: "Please enter your first name",
lname: "Please enter your last name",
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
email: "Please enter a valid email address",
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
password2: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same passwords"
},
postal_code: "Please enter a valid email address",
timezones: "Please select a time zone",
mp: "Please enter a valid mobile number. Only numbers please.",
gender: "Please select a gender",
dob: "Please enter a valid Date of Birth in mm/dd/yyyy format."
},
highlight: function(element) {
$(element).closest('.control-group').removeClass('success').addClass('error');
},
success: function(element) {
$(element).closest('.control-group').removeClass('error').addClass('success');
$(element).closest('form').find('.valid').removeClass("invalid");
},
errorPlacement: function(error, element){
error.text( element.closest('.control-group').find('.help-line') );
},
onfocusout: function(element) {
$(element).valid();
}
});
我不愿意创建一个 jsfiddle 示例,只是因为所有因素都与现场环境不同,但根据@Sparky 的建议,这里是它(感谢 Sparky) http://jsfiddle.net/DLcLJ/7/
您可以看到,如果您在字段中进行选项卡,它会正确通知您该字段无效.. 但是如果您填写数据,它将保持无效.. 如果您提交表单,则您刚刚输入的字段有效数据进入,将保持无效..嗯...