jQuery Validation PlugIn : Callback for field success validation?

12,842

You might want to check out the success option.

http://docs.jquery.com/Plugins/Validation/validate#options

$("#myform").validate({
   success: function(label) {
     label.addClass("valid").text("Ok!")
   },
   submitHandler: function() { alert("Submitted!") }
})

If you pass a function to success, you are given back the label as a jQuery object. You can then manipulate that object or a related object.


Alternatively, your error and success graphic can use a background image, and then you can swap out the background image with CSS on the validClass.

Share:
12,842
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin about 2 years

    Im am using errorPlacement to add a class to a label to show a graphic element in addition to the error text ( they are both different elements).

    Is there a way to use a callback that will fire when the validation of a field is successful? I am already using validClass, that will change the error message, but I need a call back so I can change the graphic element to a "success" one.

    For Example

    [graphic] [input field] [error text]

    I was able to change the [graphic] and the [error text] when there is an error, but when the correct value is entered in the field I was able to change the [error text] but not the [graphic].