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? It should already be an object. I see no JSON here. JSON is a textual representation of object data...but yourrulesabove looks like an actual JavaScript object literal, to me. And in any case unless you are getting the rules data from somewhere else (e.g. fetching it from a remote server via AJAX) then there would be no reason to need JSON.chkduplicate: { "table_name": "users", "fld_name": "user_id"}without the single quotes...there's no need to make it a string as far as I can see