Hi, I'm trying to create a new validation rule to check if a button has a class.

I try to explain the scenario.

I have a button that makes an ajax call to check the availability of a product.

When the app loads the button as class "to_check", when the button is clicked an ajax call is fired, a server script return the availability of the product and basing on this answer I change the class of the button from "to_check" to "ok" or "ko".

Now I want to validate the button to se if the availability is being checked and is ok, then I wrote this:

$.validator.addMethod('hasClass', function(value, element) { if($(element).hasClass(value)) { 
                                                               return true;
                                                             } else {
                                                               return false
                                                             }
                                                            }, jQuery.format('Please check the button'));

Now I want to add this rule to the button with the metadata plugin inside the class name with this syntax:

<input type="button" name="verifica_disponibilita" 
 class="to_check {validate:{hasClass:'ok', messages:{hasClass:'Verifica disponibilit&agrave;'}}}" 
 id="verifica_disponibilita" value="Verifica disponibilit&agrave;" />

When I submit the form it returns always false, I tried to log "value" and I get the button value.

How I can get the "ok" passed via the metadata class? (bold one)

Bye



-- 
gianiaz.net - web solutions
via piedo, 58 - 23020 tresivio (so) - italy
+39 347 7196482 

Reply via email to