1

I've been studying the ASP.NET MVC 5 client-side validation feature. The validation process is triggered mainly when the input element lost is focus (i.e: user stops editing it and select another element)

The built-in remote validation feature (using jQuery.validate and the Microsoft's jQuery.validate.unobtrusive library) is very important for those cases in which the form cannot be validated on the client side (like username availability on a registration form).

Sadly, I've noticed that this feature triggers the validation (and its corresponding Ajax request) essentially on every keystroke the user generate when editing the input field, meaning that, for example, if I want to check the availability of the user name "rsantanap", 9 ajax requests are generates when, actually, 8 are wasted.

Is there any way to change this behavior to only when the input element lost its focus, just like the client-side validation feature does and without inserting custom js code or JSON interception?

mdarefull
  • 829
  • 2
  • 14
  • 24
  • Your assumptions are not quite correct. All validation (including remote) is 'lazy' and is first triggered after `blur()`. From that point on validation is triggered on `keyup` –  Jul 13 '16 at 22:43
  • @StephenMuecke Thank you very much! I'm very sorry for that slip, I did take my time checking for existing answers but never realized that the client-side validation and the remote validation were related at that point and certainly didn't notice that all of them were validated on keyup! Just a noob mistake :) – mdarefull Jul 13 '16 at 22:57
  • @StephenMuecke, the "lazy" validation of the jQuery Validate plugin will also ignore the `blur` event unless something is first typed into the field, or until the submit button is clicked once. http://jsfiddle.net/m8m30mwv/ – Sparky Jul 13 '16 at 23:42
  • @Sparky, I know - I was too 'lazy' to write it all up:). But for OP's benefit - [jquery validate documentation](https://jqueryvalidation.org/documentation/) –  Jul 13 '16 at 23:46

0 Answers0