首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery.validate.unobtrusive:比较属性始终失败

jquery.validate.unobtrusive:比较属性始终失败
EN

Stack Overflow用户
提问于 2011-09-09 05:37:46
回答 2查看 2.4K关注 0票数 0

我在表单上有两个电子邮件字段来验证用户是否正确输入了他的电子邮件。但是,即使正确输入了两次电子邮件,jquery.validate.unobtrusive也始终会显示错误消息。

这是一个ASP.Net MVC3项目,我在第二个电子邮件字段中使用了Compare属性。

以下是我的网页上该区域的html代码:

代码语言:javascript
复制
<div class="editor-field">
    <input class="text-box single-line" data-val="true" data-val-length="The field Adresse de courriel must be a string with a maximum length of 50." data-val-length-max="50" data-val-required="L&amp;#39;adresse de courriel doit &amp;#234;tre sp&amp;#233;cifi&amp;#233;e" id="Requerant_Individu_Courriel" name="Requerant.Individu.Courriel" type="text" value="" />
    <span class="field-validation-valid" data-valmsg-for="Requerant.Individu.Courriel" data-valmsg-replace="true"></span>
</div>
<div class="editor-field">
    <input class="text-box single-line" data-val="true" data-val-equalto="Les deux adresses de courriel doivent &amp;#234;tre identiques" data-val-equalto-other="*.Courriel" data-val-required="L&amp;#39;adresse courriel de confirmation doit &amp;#234;tre sp&amp;#233;cifi&amp;#233;e" id="Requerant_Individu_ConfirmCourriel" name="Requerant.Individu.ConfirmCourriel" type="text" value="" />
    <span class="field-validation-valid" data-valmsg-for="Requerant.Individu.ConfirmCourriel" data-valmsg-replace="true"></span>
</div>

我在第二个电子邮件输入中注意到这个属性: data-val-equalto-other="*.Courriel“我想知道这个星号是否正确。

这是我的模型中的内容:

代码语言:javascript
复制
    [Required(ErrorMessage = "L'adresse de courriel doit être spécifiée")]
    [StringLength(50)]
    [Display(Name = "Adresse de courriel")]
    public String Courriel { get; set; }

    [Compare("Courriel", ErrorMessage = "Les deux adresses de courriel doivent être identiques")]
    [Required(ErrorMessage = "L'adresse courriel de confirmation doit être spécifiée")]
    [Display(Name = "Retapez votre adresse de courriel")]
    public string ConfirmCourriel { get; set; }

有没有人遇到过这个问题?有什么建议吗?

注意:我使用的是jQuery 1.6.3和jQuery验证插件1.8.1

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-09-09 06:11:41

我终于在这篇文章中找到了我问题的答案:

JQuery 1.5 breaks Compare Validate (JQuery Validate 1.8)

在文件jquery.validate.unobtrusive.js中,第288行:

代码语言:javascript
复制
element = $(options.form).find(":input[name=" + fullOtherName + "]")[0];

必须替换为以下代码:

代码语言:javascript
复制
element = $(options.form).find(":input[name='" + fullOtherName.replace(".", "\\.").replace("[", "\\[").replace("]", "\\]") + "']")[0];

309行也是这样:

代码语言:javascript
复制
return $(options.form).find(":input[name='" + paramName + "']").val();

它必须被替换为:

代码语言:javascript
复制
return $(options.form).find(":input[name='" + paramName.replace(".", "\\.").replace("[", "\\[").replace("]", "\\]") + "']").val();
票数 1
EN

Stack Overflow用户

发布于 2012-01-24 03:48:59

如果您使用的是最小化版本,请执行搜索/替换:

替换:

代码语言:javascript
复制
f = a(b.form).find(":input[name=" + d + "]")[0];

通过以下方式:

代码语言:javascript
复制
f=a(b.form).find(":input[name='"+d.replace(".","\\.").replace("[","\\[").replace("]","\\]")+"']")[0];

另外,请替换:

代码语言:javascript
复制
return a(b.form).find(":input[name='"+c+"']").val()

通过以下方式:

代码语言:javascript
复制
return a(b.form).find(":input[name='"+c.replace(".","\\.").replace("[","\\[").replace("]","\\]")+"']").val()
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7354835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档