The first argument, "value", refers to the actual value-attribute. You'll probably want to use the third argument, eg. "param":
$.validator.addMethod('hasClass', function(value, element, param) { reurn $(element).hasClass(param); }, jQuery.format('Please check the button')); Also a bit simpler with a single return. Jörn On Mon, Oct 19, 2009 at 9:03 PM, Giovanni Battista Lenoci <gian...@gmail.com > wrote: > 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à'}}}" > id="verifica_disponibilita" value="Verifica disponibilità" /> > > > 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 > >