views:

678

answers:

2

I want to manually trigger validation including showing error messages with jQuery Validate.

The scenario i am trying to accomplish is a form like this:

<form>
 <input id=i1> <button id=b1>
 <input id=i2> <button id=b2>
</form>

When clicking b1, only i1 should be validated. hen clicking b2, only i2 should be validated. However all fields must be posted. How can i do this? I thought about handling the click event for b1/b2 and manually validating a part of the form.

A: 

jQuery Validate plugin offers realtime validation. You can get rid of the buttons and the input fields will validate when someone fills them out. Soon as they loose focus, they get validated. This is on by default.

idrumgood
+2  A: 

That library seems to allow validation for single elements. Just associate a click event to your button and try the following:

validate().element("#i1");

Examples here:

http://docs.jquery.com/Plugins/Validation/Validator/element#element

Roberto Aloi