如何在只读字段上启用 jquery 验证? [英] How can I enable jquery validation on readonly fields?
问题描述
来自 http://jqueryvalidation.org/ 的人刚刚发布了 1.13.1 版.查看他们的网站,我在更改日志中看到了这一点:
Guys from http://jqueryvalidation.org/ just released version 1.13.1. Checking on their website i see this on the changelog:
核心:* 忽略只读和禁用字段.(9f4ba10)
CORE: * Ignore readonly as well as disabled fields. (9f4ba10)
这是链接:https://github.com/jzaefferer/j验证/提交/9f4ba10ea79b4cf59225468d6ec29911f0e53a0a
我使用了一些引导程序模板,其中一个现在使用该版本.这给我带来了一个问题,我使用 readonly 属性来防止用户手动输入日期,所以他们唯一的选择是从日期选择器中选择一个日期.
I use some bootstrap templates and one of them now uses that version. That brings me a problem, i use readonly attribute to prevent users typing dates manually, so their only option is to choose a date from the datepicker.
通过此更改,验证插件会忽略标记为必需的只读输入,谁能帮我建议一些针对 1.13.1 或未来版本的修复?我发现了一个相反的问题:我该怎么做对只读字段禁用 jquery 验证?
With this change, the validation plugin ignores the readonly inputs marked as required, can anyone help me out suggesting some fix for 1.13.1, or future versions? i´ve found a question to do the opposite: How can I disable jquery validation on readonly fields?
推荐答案
感谢您的建议 Panoptik,在focusin
上添加readonly
,然后在上去掉>focusout
是最干净的方式,万分感谢!如果有人遇到同样的问题,我会回答自己.希望有帮助.
Thank you for you suggestion Panoptik, adding readonly
on focusin
, and then removing it on focusout
was the cleanest way, million thanks! I answer myself in case anyone has the same problem. Hope it helps.
$(document).on("focusin", "#someid", function() {
$(this).prop('readonly', true);
});
$(document).on("focusout", "#someid", function() {
$(this).prop('readonly', false);
});
这篇关于如何在只读字段上启用 jquery 验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!