What I want to do:
I need to validate if a check box is selected than the drop down should be empty,
using JQuery validation plugin (jqueryvalidation - bassistance) with inline class names
what I am doing:
I am trying to add a custom validation rule using
JQuery validation plugin (jqueryvalidation - bassistance) and using 'shouldBeEmptyIf'
in the class name for the checkbox using param
/*JS function to return status of checkbox*/
function getValue(){
return $('[name=checkBox1]').prop('checked');
}
/*Form element using class for 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 the 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 be empty");
Problem I am having:
I do get the value of param[0] and param[1] but they are 'cached' they stay the same
even if I change the drop-down or select/unselect checkbox
(also tried to add getValue() function hoping to get fresh value every time but it did not worked).
It gets the initial value when the page is loaded. Is it assigning static value when page is loaded? If so how can I achieve the solution of what I want to do using JQuery validation plugin with inline class
Any help and direction toward it will be appreciated
Thank you