About this question
I have an input field out of several on a form, whose value needs to be validated against database values. I am using jquery validator to perform all other validations and trying to achieve database validation using visualforce remoting and validator method. What I am trying.
HTML Code
<input type="text" class="numVal" maxlength="6" "="" fdprocessedid="4nf8uh">
Validator Rule class and method snippet
$j.validator.addClassRules({ numVal: { required: true, number: true, noDecimal:true, checkDBList: true } }); $j.validator.addMethod("checkDBList",function(value) { MyController.searchDB(value, function(result, event){ if(event.status ){ if(result != null){ return true; }else{ return false; } } if(event.type == 'exception') { return false } }); }, "Please enter a valid number");
Problem My validator method is always returning false, even though a valid number is provided and the remote method is returning the correct status. I understand that visualforce remoting is asynchronous and both the functions are executing in different contexts and hence the issue. Any help to use the visualforce remoting in a correct way inside the validator method is appreciated.