I have some remote validation and normal validation set on some properties in my view model.
When the validation is run, I also run a function where I display a tick or a cross next to the validated field, depending on whether the field was valid or not.
This is where the remote validation is a problem. Since it is async, the validation is fired, my function the displays the tick/cross is run, and then the validation result is returned. Since I have both remote and non remote validation attributes on the property, the property can pass local validation and fail the remote validation.
When this happens, the wrong image is displayed next to my input field (tick/cross) because the function which decides which image to display is run before the remote validation returns.
The way it decides if the element is valid is by checking for the input-validation-error
class.
Is it possible to come around this? Is there a callback or event I can use?
We use the jQuery.validate lib that comes along in mvc 4.
Okay, attempt #2 at answering this.
jQuery validation's remote
currently does not support specifying callbacks, and there's no real indication this would change in the near future.
What you can do, however, is hook into jQuery's general Ajax Events and capture the ajaxComplete
or ajaxSuccess
events, after which you could check whether your validation call occurred.
It's not pretty, but it's what was suggested by the creator of the plugin.
Hope it helps