我正在使用验证插件。问题是,当我执行.valid((时,即使字段有值,它也会为每个必填字段返回一个错误。我看到控制台吐出这样的东西;
表单验证.js:835 init[span#str_grade-error.has error]
我似乎不明白为什么在满足了所需的先决条件的情况下会出现错误。
此字段已填写。
function global_form_validate_this(myobj)
{
myobj.validate({
// States
ignore: ':hidden:not([class~=selectized]),:hidden > .selectized, .selectize-control .selectize-input input',
errorClass: "has-error",
validClass: "has-success",
errorElement: "span",
// Rules
rules: {
firstname: {
required: true
},
dte_user_birthday:
{
required: true,
date: true
},
dte_tetnus:
{
date: true
},
dte_tb_test:
{
date: true
},
dte_mmr:
{
date: true
},
dte_dpt:
{
date: true
},
dte_hepb:
{
date: true
},
dte_hepa3:
{
date: true
},
dte_IPV:
{
date: true
},
dte_Meningococcal:
{
date: true
},
dte_HIB:
{
date: true
},
dte_PCV:
{
date: true
},
str_credit_card_number:
{
required: true,
creditcard: true
},
dte_season_start:
{
required: true,
date: true
},
dte_season_end:
{
required: true,
date: true
},
int_win_point_value:
{
required: true,
integer: true
},
int_loss_point_value:
{
required: true,
integer: true
},
int_tie_point_value:
{
required: true,
integer: true
},
agree: {
required: true
},
terms: {
required: true
},
username: {
required: true
},
combo: {
required: true
},
str_league_email: {
required: true,
email: true
},
howmuchnow: {
required: true,
// money: true
},
str_organization_email: {
required: true,
email: true
},
str_frontdesk_email: {
required: true,
email: true
},
str_email: {
required: true,
email: true
},
email: {
required: false,
email: true
},
city: {
required: true
},
useremail: {
required: true,
email: true
},
str_email_current: {
required: true,
email: true
},
website: {
required: true,
url: true
},
language: {
required: true
},
upload1: {
required: true,
extension: "jpg|png|gif|jpeg|doc|docx|pdf|xls|rar|zip"
},
str_email_current_check:
{
equalTo: '#str_email_current'
},
inputname: {
required: true
},
comment: {
required: true,
minlength: 30
},
security_code: {
required: true,
integer: true,
minlength: 6
},
mobile_phone: {
require_from_group: [1, ".phone-group"]
},
home_phone: {
require_from_group: [1, ".phone-group"]
},
password: {
required: true,
minlength: 4
},
str_ccv_number: {
required: true,
minlength: 3
},
repeatPassword: {
required: true,
minlength: 4,
equalTo: '#password'
},
zip: {
required: true,
minlength: 5
},
team: {
required: false,
minlength: 5
},
fname: {
required: false,
minlength: 2
},
lname: {
required: false,
minlength: 2
},
mobile: {
required: true
},
mobile1: {
required: true
},
verification: {
required: true,
smartCaptcha: 19
},
applicant_age: {
required: true,
min: 16
},
int_agegroup_max: {
required: true,
max: 98
},
licence_no: {
required: function(element) {
return $("#applicant_age").val() > 19;
}
},
child_name: {
required: "#parents:checked"
}
},
/* @validation error messages
---------------------------------------------- */
messages: {
firstname: {
required: 'Enter first name'
},
agree: {
required: 'You must check this box.'
},
terms: {
required: 'You must check this box.'
},
lastname: {
required: 'Enter last name'
},
city: {
required: 'Please enter a valid city.'
},
useremail: {
required: 'Enter email address',
email: 'Enter a VALID email address'
},
website: {
required: 'Enter your website URL',
url: 'URL should start with - http://www'
},
language: {
required: 'Select language'
},
upload1: {
required: 'Please select file',
extension: 'File format not supported'
},
inputname: {
required: 'Please select model'
},
comment: {
required: 'Add comments please.',
minlength: 'Enter at least 30 characters or more'
},
mobile_phone: {
require_from_group: 'Add a mobile number'
},
security_code: {
required: 'Enter a six digit NUMERICAL security code.',
minlength: 'Enter a six digit NUMERICAL security code.',
integer: 'Enter a six digit NUMERICAL security code.'
},
home_phone: {
require_from_group: 'Add a phone number'
},
password: {
required: 'Please enter password'
},
repeatPassword: {
required: 'Please repeat password',
equalTo: 'Password does not match'
},
mobile: {
required: 'Please select model'
},
mobile1: {
required: 'Please select model'
},
verification: {
required: 'Please enter correct number',
smartCaptcha: 'Wrong number. Please recalculate'
},
applicant_age: {
required: 'Enter age',
min: 'Must be 16 years or above'
},
licence_no: {
required: 'Enter licence number'
},
int_agegroup_max: {
required: 'Enter age',
max: 'Please enter a valid age range.'
},
child_name: {
required: 'Child name not entered'
}
},
/* @validation highlighting + error placement
---------------------------------------------------- */
highlight: function(element, errorClass, validClass) {
$(element).parent().addClass(errorClass).removeClass(validClass);
},
unhighlight: function(element, errorClass, validClass) {
$(element).parent().removeClass(errorClass).addClass(validClass);
},
errorPlacement: function(error, element)
{
if($(".has-error").length > 0){
$('.accordion_missing_data').show();
}
console.log(error);
// qTip call
if (!$(element).hasClass('valid')) {
if (error.html() != "") {
$(element).parent().qtip({
content: {
text: error.html()
},
style: {
width: 200,
classes: 'qtip-red tip-tipped',
tip: true
},
position: {
my: 'bottom center',
at: 'top center',
target: $(element)
},
show: {
when: false,
ready: true
},
hide: false
});
}
}
},
success: function(label, element) {
// Hide tooltips on valid elements
$(element).not('.error').qtip('hide');
}
});
}
这是由隐藏div中的字段引起的,但这些字段不一定隐藏在输入本身上(display:none(。因此,即使浏览器看不到它,验证器也能看到它。