[英]JQuery validation engine
我添加了以下指定的自定義“ func”驗證規則
"requiredPrice": {
"func": function (field, rules) {
return (field.val() && field.val() != '')
},
"alertText": "* Price is required"
}
並在html中添加了適當的類
<input class="validate[custom[requiredPrice]]" type="text" id="fixed-price" data- bind="value: PriceFixed" readonly="readonly" />
如果value為空,則驗證函數返回false,但是
modifyLineForm.validationEngine('validate');
仍然返回true
這是我的出乎意料的猜測。 請嘗試使用它。
class="validate[funcCall[requiredPrice]]"
有關更多詳細信息,請參閱: http : //posabsolute.github.io/jQuery-Validation-Engine/#validators/funccall-methodname
謝謝!
在JQuery Validation Engine 2.6.2中,存在一個與在驗證規則中使用函數有關的bug,因此即使開發人員提供的演示也不起作用。
幸運的是,在我的特殊情況下,我只需要更改某些控件的“必需”驗證規則的默認消息,因此我決定使用“ custom_error_messages”。
HTML:
<input class="validate[required] price" type="text" id="fixed-price" data- bind="value: PriceFixed" readonly="readonly" />
JavaScript的:
$('#modify-line-form').validationEngine({
'custom_error_messages': {
'.price': {
'required': {
'message': "* Price is required"
},
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.