每个多个字段集的jQuery验证,如何使用不同的事件触发每个节的验证 [英] jQuery validation per multiple fieldsets, how to use different event to trigger validation per section

查看:72
本文介绍了每个多个字段集的jQuery验证,如何使用不同的事件触发每个节的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常非常长的表格(大约300个字段),我使用这种巧妙的 <a id="step0Next" class="next" href="#">Next ></a>

I have a really, really long form (about 300 fields) that I broke down into different sections using this slick jQuery plugin Form Wizard. If you group your form into different fieldsets, the FormWizard will automagically display one section at a time, with a Next hyperlink to take you to the next section:
<a id="step0Next" class="next" href="#">Next ></a>

我的问题是:使用jQuery Validation插件,如何在用户单击下一步"等等时验证每个字段集,而不是使用提交"按钮.换句话说,如何将触发事件从提交"更改为六个单独的部分的六个不同的超链接?

My question is this: Using the jQuery Validation plugin, how can I validate each fieldset when a user clicks Next, and so forth, instead of using the Submit button. Put differently, how can I change the trigger event from Submit to six different hyperlinks for six separate sections?

感谢帮助此新手.

推荐答案

我不认为这是一个简单的解决方案,但是我在当前项目中做了类似的事情.

I don't think this is a trivial solution, but I have done something similar in my current project.

1)将事件绑定到每个下一个链接.在这种情况下,您将使用jquery验证插件的 element 方法手动验证字段集中的每个输入.

1) Bind an event to each next link. In the event, you are going to validate each input in the fieldset manually using the element method of the jquery validation plugin.

2)在事件中,获取当前字段集.您的插件可能可以为您跟踪此操作,但是我对此并不熟悉.

2) In the event, get the current fieldset. Your plugin can probably keep track of this for you, but I'm not familiar with it.

3)在字段集中搜索其所有输入,然后分别进行验证.

3) Search the fieldset for all of its inputs and validate them individually.

4)如果该字段集中的任何输入无效,请不要前进到下一页.

4) If any of the inputs in the fieldset are invalid, don't advance to the next page.

每当单击下一个链接时,以下代码段便会手动验证字段集中的非隐藏输入.它没有显示如何检索字段集和验证器,或者如果表单无效则如何停止前进到下一个字段集.您的表单插件可以帮助您解决此问题.从该示例中可以得到的是,您可以使用jquery验证插件手动验证字段集中的所有输入.

The following piece of code manually validates the non hidden inputs in a fieldset whenever the next link is clicked. It does not show how to retrieve the fieldset and validator or how to stop the progression to the next fieldset if the form is invalid. Your form plugin may be able to help with this. What you should get out of this example is that you can manually validate all the inputs in a fieldset using the jquery validation plugin.

$('.next').bind('click', function() {
 var inputs = myFieldset.find(':input:not(:hidden)');
 for (var i = 0; i < inputs.length; i++) {
   myValidator.element($(inputs[i]));
 }
});

这篇关于每个多个字段集的jQuery验证,如何使用不同的事件触发每个节的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆