1

I'm using jQuery Validation Plugin in order to verify form on client side.

One of my requirements is that form must be validated as client type in input or textarea fields. jQuery Validation Plugin has an option onkeyup, but it's same as without it.

For testing purposes, I created jsfiddle demo.

What can be done?

Sparky
  • 98,165
  • 25
  • 199
  • 285
RhymeGuy
  • 2,102
  • 5
  • 32
  • 62

1 Answers1

6

We generally use the keyup event for this purpose. So you should simply add a function to be executed when the keyup event is fired, like this:

onkeyup: function( element, event ) {
    $(element).valid();
}

If you look at the code of the plugin, you'll see that the keyup method will pass the element (the input element or textarea) and the event object every time the keyup event is fired: you can use them to customize the behavior. The valid() method simply checks if the selected element is valid and shows the appropriate message.

See your jsfiddle example updated: http://jsfiddle.net/yjgQG/2/

Sparky
  • 98,165
  • 25
  • 199
  • 285
taseenb
  • 1,378
  • 1
  • 16
  • 31
  • Well this certainly work, and therefore I'll mark it as answer. Thanks! – RhymeGuy Dec 07 '13 at 00:32
  • Validating "on key up" is the default operation of the plugin. You should not need to specify the `onkeyup` option in this case. See: http://jsfiddle.net/yyR9C/ – Sparky Dec 07 '13 at 00:39
  • Looks like Sparky is using an older version (1.10) while RhymeGuy the latest (1.11.1). Probably they behave differently. The demos on his page do not validate on keyup: http://jquery.bassistance.de/validate/demo/ (or maybe a bug?) – taseenb Dec 07 '13 at 00:50
  • My mistake... _immediate_ `onkeyup` validation was a bug in version 1.10. In the latest version (1.11.1), you have to submit the form or leave focus before you'll get any `onkeyup` behavior on a field. Please edit your answer so it unlocks the voting... then I'll remove my down-vote. – Sparky Dec 07 '13 at 00:50
  • 1
    Yes, a bug in version 1.10 - https://github.com/jzaefferer/jquery-validation/issues/541 – Sparky Dec 07 '13 at 00:50
  • +1, reversed my vote. I should have read my own previous answer about proper behavior: http://stackoverflow.com/a/15104059/594235 – Sparky Dec 07 '13 at 01:02