经过多方努力,我完全无法让addMethod工作。
我的代码如下:
$("#submitform").validate(
{
rules: {
org_name: "required",
email_address: "required",
phone: "required",
abn: "required",
description: "required",
geocomplete: "required"
},
messages: {
org_name: "Required",
email_address: "Required",
phone: "Required",
abn: "Required",
description: "Required",
geocomplete: "Required"
},
submitHandler: function(event, validator) {
// submitForm();
},
invalidHandler: function(event, validator) {
//code..
}
});
addMethod
$.validator.addMethod("org_name", function(value) {
// return this.optional(element) || value == params[0] + params[1];
console.log("hi" + value);alert('hi');
return false;
}, "Invalid");
和目标元素
<input id="org_name" name="org_name" type="text" class="input-xlarge ">
没有调用addMethod函数,没有错误,我对此感到茫然? 另一方面,“必需”验证在表单上正常工作正常,这是我第一次涉足这个插件。
答案 0 :(得分:3)
使用像
这样的规则 org_name: "org_name",
您的代码应该是,
$("#submitform").validate(
{
rules: {
org_name: "org_name",// input element: method name
email_address: "required",
phone: "required",
abn: "required",
description: "required",
geocomplete: "required"
},