【发布时间】:2014-10-30 16:38:02
【问题描述】:
我将最新版本的 jQuery Validation Unobtrusive 与最新版本的 jQuery Validate 结合使用。验证本身就像一个魅力。但是,如果该字段无效,则会将值添加到 aria-describedby 属性中。
假设我想输入我的密码(验证密码的长度必须大于 6)。初始 HTML 如下所示:
<input data-val="true" data-val-minlength="The field Passwort must be a string or array type with a minimum length of '6'."
data-val-minlength-min="6" data-val-required="The Passwort field is required."
id="Password" name="Password" tabindex="2"
type="password">
我开始输入一个只有 5 个字符的密码,然后通过单击 body 上的某个位置将焦点从 input 移开。验证通过并添加一系列属性和值,包括aria-describedby。现在aria-describedby 属性只有一个值Password-error。如果我然后再次聚焦输入字段并删除所有字符,甚至继续按退格键,则会在每个键上添加一个新值。结果如下:
<input data-val="true"
data-val-minlength="The field Passwort must be a string or array type with a minimum length of '6'."
data-val-minlength-min="6"
data-val-required="The Passwort field is required."
id="Password" name="Password" tabindex="2" type="password" aria-required="true"
aria-invalid="true" class="input-validation-error"
aria-describedby="Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error Password-error
Password-error">
考虑到值相等,这对于属性的值来说是相当大的开销。这种行为是常见的还是有人知道如何解决这个问题?
【问题讨论】:
-
你找到解决办法了吗?
-
在下面查看我的答案。在我在 VS 中重建解决方案并删除了在后台创建的卷影副本后,问题就以某种方式消失了。
标签: javascript jquery unobtrusive-validation