JQuery 工具验证器在表单元素动态增长时出现错误
function testOptionalFieldsValidation(el){
group = getGroup(el);
return validateGroup(group);
}
function getGroup(el){
return $(el).parents('.field');
}
function validateGroup(group){
var count = 0;
$(group).find("input[type!='hidden'], select").each(function(){
if( $(this).val() )
count++;
});
if($(group).find("input[type!='hidden'], select").length == count || count == 0)
return true;
else
return false;
}
$.tools.validator.fn(
$("#addressInfo .field select, #addressInfo .field input[type!='hidden']"),
"Please Complete this mandatory field",
function(el, v){
if( !testOptionalFieldsValidation(el) && ($(el).val().length == 0 ) )
return false;
else
return true;
}
);
$('#addressInfo div.links .add').live('click',function(){
$('form').data('validator').destroy();
$('form').validator().bind("onBeforeFail", function(e, els) {
els.css('border','1px solid #F00');
if (!els.is(':visible') ) {
els.css('border','1px solid #F00');
els.css('width', els.next().width());
els.css('top', els.next().position().top + 1);
els.css('left', els.next().position().left + 6);
els.css('visibility', 'hidden');
els.css('position', 'absolute');
els.css('display', 'block');
els.next().bind('blur', function() {
els.trigger('keyup');
});
}
});
$.tools.validator.fn(".select .required", function(input, value) {
return value.length >= 1 ? true : {
en: "Please select this Mandatory field"
};
});
});
正如您可以看到上面提到的代码块 $('#addressInfo div.links .add').live('click',function() 定义。我为验证器调用析构而不是构造,以便它可以采用我的可选字段块地址信息部分只需单击每个块上的加号锚点即可扩展)。比上面提到的步骤之后,我什至调用我自己的规则检查函数来与验证器关联以验证我的期望字段。请帮助我解决这个问题。谢谢
function testOptionalFieldsValidation(el){
group = getGroup(el);
return validateGroup(group);
}
function getGroup(el){
return $(el).parents('.field');
}
function validateGroup(group){
var count = 0;
$(group).find("input[type!='hidden'], select").each(function(){
if( $(this).val() )
count++;
});
if($(group).find("input[type!='hidden'], select").length == count || count == 0)
return true;
else
return false;
}
$.tools.validator.fn(
$("#addressInfo .field select, #addressInfo .field input[type!='hidden']"),
"Please Complete this mandatory field",
function(el, v){
if( !testOptionalFieldsValidation(el) && ($(el).val().length == 0 ) )
return false;
else
return true;
}
);
$('#addressInfo div.links .add').live('click',function(){
$('form').data('validator').destroy();
$('form').validator().bind("onBeforeFail", function(e, els) {
els.css('border','1px solid #F00');
if (!els.is(':visible') ) {
els.css('border','1px solid #F00');
els.css('width', els.next().width());
els.css('top', els.next().position().top + 1);
els.css('left', els.next().position().left + 6);
els.css('visibility', 'hidden');
els.css('position', 'absolute');
els.css('display', 'block');
els.next().bind('blur', function() {
els.trigger('keyup');
});
}
});
$.tools.validator.fn(".select .required", function(input, value) {
return value.length >= 1 ? true : {
en: "Please select this Mandatory field"
};
});
});
As you can see above mention Code block $('#addressInfo div.links .add').live('click',function() definition. I call a destruct for validator than construct so that it can take my optional fields block of Address Info section which grow by simply clicking a plus sign anchor against each block). Than after above mention step i even call my own rule check function to be associate with validator to validate my desire fields. Please help me with regards to it. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我调用验证器构造函数来重新初始化所有内容。
I call a validator constructor to reinitialize everything..