javascript - jQuery custom validator method getting called whenever element changes -


i have select target of custom validator method.

validator:

    var validator = $("#myform").validate({         rules : {             source: "source_selected",         },         messages : {         },         errorlabelcontainer: $("#error_container ul"),          errorcontainer: $("#error_container"),          wrapper : "li"            }); 

custom validator method:

    $.validator.addmethod("source_selected", function(value, element) {         var source_id = $(element).selectedvalues();         if(source_id == 0) {              return false;         }          return true;     }, "please select source copy subscriptions from."); 

select:

<select name="source" id="source">     <option value="0">-- choose --</option>     <? foreach($managers $id => $name) { ?>     <option value="<?=$id?>"><?=$name?></option>     <? } ?> </select> 

everytime change option in select source_selected function gets called. if put alert in there gets triggered everytime click out of select box (similar .blur). want called when submit button gets called.

submit click event:

    $("#submit_button").click(function() {          var valid = validator.form();         if (valid) {             document.myform.submit();         }     }); 

any thoughts appreciated.

instead of doing validator - seems useless - call validation function in onsubmit, , check return value of it.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -