jQuery.validator.addMethod回调方法参数NaN问题 [英] jQuery.validator.addMethod callback method parameters NaN issue

查看:323
本文介绍了jQuery.validator.addMethod回调方法参数NaN问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要:由于某种原因,传递给jQuery.validator.addMethod的回调函数的参数是

Summary: For some reason, the parameters getting passed to the callback function of jQuery.validator.addMethod is

NaN

.我不明白为什么将规则添加到适配器时,一切都会正确传递.我正在使用jQuery Validation插件1.8.0并在FF 3.5.3.上进行测试.

谢谢你的帮助!

其他详细信息:在jQuery.validator.addMethod的回调方法中,params 参数始终为NaN而不是object.我在这里想念什么吗?

这是相关的jquery代码:

. I can''t understand why as when adding the rule to the adapters, everything is getting passed correctly. I''m using the jQuery Validation Plugin 1.8.0 and testing on FF 3.5.3.

Thanks for any help!

Additional Details: Within the jQuery.validator.addMethod''s callback method, the params parameter always is NaN instead of object. Am I missing something here?

Here''s the relevant jquery code:

jQuery.validator.unobtrusive.adapters.add('myrule', ['p1', 'p2'], function (options) {
options.rules['myrule'] = { p1: options.params.p1, p2: options.params.p2};
...
});

 jQuery.validator.addMethod('myrule', function (value, element, params) {
//business logic here.

//value of params is NaN. I debugged within the jquery.validate.js- var rule = { method: method, parameters: rules[method] };  rules[method] is NaN

}, '');

推荐答案

原因是我实际上使用了关键字viz之一. ''minlength''(当我在上面发布问题时,我在上面用''myrule''掩盖了.将规则的名称从''minlength''更改为其他名称可以解决此问题.
The reason was that I had actually used one of the keywords viz. ''minlength'' (which I had masked above as ''myrule'' when I posted my question above. Changing the name of the rule from ''minlength'' to something else resolved the issue.


这篇关于jQuery.validator.addMethod回调方法参数NaN问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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