4
在自定義驗證方法中,我想調用minLength驗證方法。Jquery驗證:在另一種方法內調用驗證方法
我已經試過這樣:
$.validator.addMethod("myMethod", function (value, element, params) {
var minLengthResult = $.validator.methods.minlength.call(this, value, element);
if(minLengthResult === false) {
return true;
}
// check the value
});
但是,如果我調試驗證MINLENGTH方法的參數對象是不確定的,而函數總是返回false。
// http://docs.jquery.com/Plugins/Validation/Methods/minlength
minlength: function(value, element, param) {
// param is undefined if i call this function using
// $.validator.methods.minlength.call()
var length = $.isArray(value) ? value.length : this.getLength($.trim(value), element);
return this.optional(element) || length >= param;
},
是否有任何方式調用驗證方法,並提供所需的參數?
這裏是一個鏈接一個工作小提琴:http://jsfiddle.net/Tumtum/4bQtm/ – Tumtum
這可能工作,但不能解決問題。我想適當地使用jquery unobtrusive驗證插件。 – Catalin