javascript - Add JQuery validation plugin custom method using param with class name -


what want do:
i need validate if check box selected drop down should empty, using jquery validation plugin (jqueryvalidation - bassistance) inline class names


what doing:
i trying add custom validation rule using jquery validation plugin (jqueryvalidation - bassistance) , using 'shouldbeemptyif' in class name checkbox using param

/*js function return status of checkbox*/ function getvalue(){     return  $('[name=checkbox1]').prop('checked'); }   /*form element using class validation - jquery validation plugin*/ <input type="checkbox" name="checkbox1" class="{shouldbeemptyif: [getvalue() , $('[name=dropdownelement]').val())=='']}">  <select name="dropdownelement" size="1" >            <option value="1">one</option>            <option value="2">two</option>  </select>   /*custom method added in additional-methods.js of jquery validation plugin*/ jquery.validator.addmethod("shouldbeemptyif", function(value, element, param) {     console.log("param[0]: " + param[0] + "  param[1]: " + param[1]);     return ( param[0] && param[1] ); }, "this field must empty"); 


problem having:
value of param[0] , param[1] 'cached' stay same if change drop-down or select/unselect checkbox (also tried add getvalue() function hoping fresh value every time did not worked).

it gets initial value when page loaded. assigning static value when page loaded? if how can achieve solution of want using jquery validation plugin inline class

any , direction toward appreciated

thank you

after trying find few different ways ended using way, thought might helpful others if trying similar thing.

instead of passing value of elements, passing names of elements (or id of element if want) , in additional method getting current value of element using passed name/id , worked. .

below updated code:

/*updated html form element*/ <input type="checkbox" name="checkbox1" class="{shouldbeemptyif: [checkbox1 , dropdownelement]}">  <select name="dropdownelement" size="1" >            <option value="1">one</option>            <option value="2">two</option>  </select>   /*updated additional method*/ jquery.validator.addmethod("shouldbeemptyif", function(value, element, param) {     var valid =true;     if($('[name='+ param[0] +']').prop('checked') && $('[name='+ param[1] +']').val()!=''){         valid = false;     }     return valid;  }, "this field must empty"); 

hope might help.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -