jquery.validate诉1.9忽略了一些隐藏的输入 [英] jquery.validate v. 1.9 ignores some hidden inputs

查看:179
本文介绍了jquery.validate诉1.9忽略了一些隐藏的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与1.7版的一切工作正常,所有隐藏的投入得到验证,

1.9版本做一些有的没有

我使用asp.net MVC 3和jquery.validate + jquery.unobtrusive(jQuery的1.7.1)

with version 1.7 everything works ok, all hidden inputs get validated,
but with version 1.9 some do and some don't
I use asp.net mvc 3 and jquery.validate + jquery.unobtrusive (jquery 1.7.1)

这是生成的HTML:

    <!--this gets validated-->
        <input type="hidden" data-val="true" data-val-number="The field Chef must be a number." data-val-required="The Chef field is required." value="" name="Chef" id="Chef">    
<span data-valmsg-replace="true" data-valmsg-for="Chef" class="field-validation-valid"></span>

    <!--this one is ignored-->
        <input type="hidden" data-val="true" data-val-number="The field MyFruit must be a number." data-val-required="The MyFruit field is required." value="" name="MyFruit" id="MyFruit">
<span data-valmsg-replace="true" data-valmsg-for="MyFruit" class="field-validation-valid"></span>

有人知道为什么会发生这种事?

anybody knows why could this happen ?

推荐答案

使用1.9版本的验证插件忽略:通过的元素:// bassistance由Matchi.com提供回到/ 2011/10/07 /释放验证-插件-1-9-0 />默认

With 1.9 version validation plugin ignores :hidden elements by default.

另一个变化应该与隐藏要素的形式设置
  更容易,这些都是现在默认忽略(选择忽略了
  :隐藏现在为默认值)。在理论上,这可能会破坏现有的
  建立。在不可能的情况下,它实际上没有,你可以解决它
  设置忽略选项为[](方括号无
  引号)。

Another change should make the setup of forms with hidden elements easier, these are now ignored by default (option "ignore" has ":hidden" now as default). In theory, this could break an existing setup. In the unlikely case that it actually does, you can fix it by setting the ignore-option to "[]" (square brackets without the quotes).

由于您使用的是不显眼的版本,你可以不设置任何选项。所以,你不初始化插件自己,为此你必须改变它的初始化后,它的设置。你能解决这个问题是这样的:

Because you're using unobtrusive version, you can't set any option. So you don't init plugin yourself, therefor you have to change it's setting after it's initialized. You can fix it like this:

var validatorSettings = $.data($('form')[0], 'validator').settings;
validatorSettings.ignore = "";

在标记

这code适用于第一个格式元素,您可以指定表格(S)和改变默认的行为。

This code works for first form element in the markup, you can specify your form(s) and change default behaviour.

这篇关于jquery.validate诉1.9忽略了一些隐藏的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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