如何在只读字段上启用jquery验证? [英] How can I enable jquery validation on readonly fields?

查看:154
本文介绍了如何在只读字段上启用jquery验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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/jquery-validation/commit/9f4ba10ea79b4cf59225468d6ec29911f0e53a0a

我使用一些引导模板,其中一个现在使用该版本。这给我一个问题,我使用readonly属性来阻止用户手动输入日期,所以他们唯一的选择是从datepicker选择一个日期。

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或将来的版本?我发现了一个相反的问题:我如何在readonly字段上禁用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屋!

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