aralejs / validator

Form Validator Widget
aralejs.org/validator/
41 stars 28 forks source link

细化rule属性getter方法中对required的判断 #67

Closed nuintun closed 10 years ago

nuintun commented 10 years ago

原始getter方法杀伤力太大,造成类似customrequired的rule被误伤!

afc163 commented 10 years ago

感谢 pull request ,要是能增加下用例就更好了。

nuintun commented 10 years ago

@afc163 :smile: 下次会注意,这次bug的测试写这里吧~

添加下面的验证规则:

validator.addRule('customrequired', function (options){
    return options.element.val() !== '0';
}, '请选择{{display}}');

后面调用的时候:

validator.addItem({
    element: '#custom',
    rule: 'customrequired'
});

因为以前的required处理,customrequired会被替换成custom,照成在rules中找不到对应的验证规则而报错!