I have a custom validation rule, so I am using to check it using addMethod. On rules, I am sending some JSON formatted string to be fetched on the addMethod
.
$.validator.addMethod("chkduplicate", function(value, element, params) {
console.log(params);
}, "This field value already exists.");
Rules should look like:
rules: {
meter_id: {
required: true,
digits: true,
chkduplicate: '{ "table_name": "users", "fld_name": "user_id"}'
}
}
here chkduplicate
is the parameter I am sending to addMethod, but when I try to console the params, it always returns true, but it should be {"table_name": "users", "fld_name": "user_id"}'
I am using this plugin
params Type: Object parameters specified for the method, eg for min: 5, the parameter is 5, for range: [1, 5] it's [1, 5]
Yours is string; try this
rules: {
meter_id: {
required: true,
digits: true,
chkduplicate: { "table_name": "users", "fld_name": "user_id"}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.