Reputation: 11
I have a Custom Validator on ASP.net MVC 5. The server code works fine, but my client code doesn't work.
In the client I have this code:
$.validator.unobtrusive.adapters.add("birth", {}, function (options) {
options.messages['birth'] = options.message;
});
$.validator.addMethod("birth", function (value, element, params) {
return false;
});
$.validator.unobtrusive.parse(document);
The adapter add method work fine because the html tag contains the data-val-birth attribute with the error message indicated in the model, but when I submit the form, the validation doesn't work.
The javascript files are included and all seems to be well done. I've tried everything.
Help, please!
Thanks in advance.
Upvotes: 0
Views: 534
Reputation: 11
I solved the problem with this code:
$.validator.unobtrusive.adapters.add("birth", function (options) {
$.validator.addMethod("data-val-birth", function (value, element, params) {
return false;
}, options.message);
});
$.validator.unobtrusive.parse(document);
I'm not convinced, but it works. I will continue researching this.
Upvotes: 1