I cannot seem to find any information on how to get custom MVC 4 unobtrusive validation to work on individual records within a grid (client-side). Server-side validation works correctly, but the client validation function is never called. For built-in MVC validations such as the [Required] attribute it works fine on both the server and client, but any validations I've created myself do not.
I know the grid uses Kendo Validator internally, but I am not sure how to register my custom validation functions with it, if it's not supposed to just pick them up from the ones I've registered with jQuery validate like so:
I don't think there's anything wrong with my custom attribute since it works on standard HTML form elements, but I guess I need to do something differently to make Kendo aware of it.
Are there any examples of doing this that I've missed? The documentation doesn't seem to cover using this with the Grid at all.
8 Answers, 1 is accepted
Thanks for your response.
I saw similar code on this page but wasn't quite clear on how to use it with a grid created by the MVC extensions. My solution was to set the field's validation property in the DataBound event:
Not sure if this is the proper way but it seemed to work. However, I was hoping that the grid could pick up the unobtrusive validation automatically instead of setting a validation function explicitly on each field. Is this not supported by Kendo?
The second problem that I ran into with this is that Kendo seems to block editing when there are validation errors. I have some fields that need to be validated based on other columns in the grid; for example Field 1 might be a dropdown, and Field 2 is an input that may or may not be required based on the value selected in Field 1. If I check that Field 2 is filled in when the value of Field 1 is changed and return false if not, a validation error will appear on Field 1 and the user won't be able to change Field 2 until they reset the value in Field 1 again (which would be somewhat tedious). Can this behavior be disabled?
In order to use the custom attribute in the Grid, you should extend the Kendo Validator with the rule. We have a demo(Custom validator editing) that demonstrates this scenario in the examples project included with the installation.
I am not sure if I understand correctly the scenario with editing the other field. Are you using InCell editing? If yes, then you should use a custom validation rule instead of the built-in required validation in order to allow the other field to be edited when no value is set and return true.
Might I suggest adding this to the online demos? Seems like something a lot of people would be looking for.
Thank you for the feedback. We will consider adding an online custom validation demo for the next release.Regards,