表单验证时颜色框调整大小(jQuery 验证)
好的,事情是这样的:
我通过 AJAX 调用 Colorbox 中的表单,并设置了一个回调来处理其验证,效果很好。唯一的问题是,当我尝试在字段无效时调整框大小(这会生成带有一类错误的标签)时,仅在第二次尝试时有效。
我在单击事件上调用调整大小方法,它仅在第二次单击时有效。
我怀疑这是因为它试图在生成标签之前调整大小......我不知道如何规避这个问题。任何帮助将不胜感激。
$(".colorbox").click(function(e) {
e.preventDefault();
var el = $(this),
sdHref = (el.attr("data-sd-href") ? el.attr("data-sd-href") : el.attr("href")),
sdTitle = (el.attr("data-sd-title") ? el.attr("data-sd-title") : el.attr("title")),
sdIframe = (el.attr("data-sd-iframe") ? true : false),
sdWidth = (el.attr("data-sd-width") ? el.attr("data-sd-width") : false),
sdHeight = (el.attr("data-sd-height") ? el.attr("data-sd-height") : false);
$.colorbox({
href: sdHref,
title: sdTitle,
iframe: sdIframe,
width: sdWidth,
height: sdHeight,
scrolling: false,
onComplete: function() { // I validate the form once the content is loaded
$("form").validate({
rules: {
phone: {
minlength: 10,
maxlength:10,
digits: true
}
}
});
}
});
});
$('body').click(function(event) { // Even bubbling works on clicking the button, but only on the second try...
if ($(event.target).is('button[type=submit]')) {
$.colorbox.resize();
}
});
Okay so here's the deal :
I call the form in Colorbox through AJAX, and have set up a callback to handle its validation, which works fine. Only problem is, when I try to resize the box when fields are invalid (which generates a label with a class of error), in only works on the second try.
I call the resize method on a click event, and it works only at the second click.
I suspect this is because it tries to resize before the labels are generated...I don't know how to circumvent that issue. Any help would be appreciated.
$(".colorbox").click(function(e) {
e.preventDefault();
var el = $(this),
sdHref = (el.attr("data-sd-href") ? el.attr("data-sd-href") : el.attr("href")),
sdTitle = (el.attr("data-sd-title") ? el.attr("data-sd-title") : el.attr("title")),
sdIframe = (el.attr("data-sd-iframe") ? true : false),
sdWidth = (el.attr("data-sd-width") ? el.attr("data-sd-width") : false),
sdHeight = (el.attr("data-sd-height") ? el.attr("data-sd-height") : false);
$.colorbox({
href: sdHref,
title: sdTitle,
iframe: sdIframe,
width: sdWidth,
height: sdHeight,
scrolling: false,
onComplete: function() { // I validate the form once the content is loaded
$("form").validate({
rules: {
phone: {
minlength: 10,
maxlength:10,
digits: true
}
}
});
}
});
});
$('body').click(function(event) { // Even bubbling works on clicking the button, but only on the second try...
if ($(event.target).is('button[type=submit]')) {
$.colorbox.resize();
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的解决方案:
my solution:
我找到了解决方案:
I found the solution :