jQuery validate插件-重置表单的特定部分 [英] Jquery validate plugin - reset specific sections of the form

查看:416
本文介绍了jQuery validate插件-重置表单的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用淘汰赛,我需要重置某些模板,而不是整个表格. resetForm()重置所有内容.有人遇到过这个吗?

Using knockout, I need to reset certain templates, not the entire form. resetForm() resets everything. Anyone ran across this before?

我看过

I've looked at this post. I could probably do something like that. It just seems like it would get real messy fast with so many various fields and validation rules.

推荐答案

我目前正在使用敲除和jquery验证项目.我要解决的一件事是将用户输入划分为多个小节,这些小节本质上在同一页面上具有多种形式.将它们全部组合在一起,这就是用户看到的总表单".

I'm working on a project with knockout and jquery validate at the moment. One thing I've settled upon is dividing the user input into subsections, essentially having multiple forms on the same page. Combine them all together and that's the total 'form' the user sees.

(此外:之所以这样做,是因为我要提交的API与表单/UI/营销部门对用户体验的期望不同.每个<form>本质上是一个不同的API输入部分,但是营销部门希望能够任意订购用户输入,因此我按班级收集它们:

(Aside: I'm doing this because the API I'm submitting to has different expectations from what the form/UI/marketing dept. expects of the user experience. Each <form> is essentially a different API input section, but the marketing dept wanted to be able to order the user inputs arbitrarily, so I'm gathering them up by class:

<form class="api1">
     ... some inputs
</form>
<form class="api2">
    ... some different inputs
</form>
<form class="api1">
    ... some more inputs
</form>

我要通过Ajax提交这些文件(这是一个单页应用程序),因此我并没有因此而从标准表单/操作/提交/发布模型中丢失任何东西.但是将其应用于您的情况,然后您可以进行以下操作:

I'm submitting these by Ajax (it's a single page app), so I'm not really losing anything from the standard form/action/submit/post model by doing this. But applying this to your situation, you could then essentially go:

$("#sectionId form.api1").each(function() {
    $(this).validate().reset();
});

我可能弄错了语法,我没有在jQuery validate上使用reset函数.但是现在我考虑了一下,如果我愿意的话,我可能可以保存一些代码...

I may have gotten that syntax wrong, I'm not using the reset function on jQuery validate. But now that I think about it, I probably could save some code if I did...

随时发布一些代码,我可以更好地适应您的问题.

Feel free to post some code and I can better adapt my solution to your problem.

这篇关于jQuery validate插件-重置表单的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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