PDA

View Full Version : Order of execution of code for Validator



jaime.brito
19 Feb 2015, 4:07 AM
Hello,

I have a combobox with the following code:



validator: function(value) {
var ccp;

CCP_proc({
MEMB_CD : client_setup.memb_cd

}, function(res){

ccp=res.resultSets[0][0].CCP;

}, this);


if(ccp!=client_setup.ccp)
return "WRONG CCP";
else return true;
}


The problem appears to be that the if statement is executed before the function CCP_proc (its a call to a database server) gets the value of ccp.

What am I doing wrong and how can I make the if statement to be executed only after the function.

Thank you,
Jaime

joel.watson
6 Mar 2015, 7:45 AM
Hi--

You could make the remote AJAX call synchronous, but that's typically undesirable from a UX perspective. Maybe a better approach would be to add a change handler to your field which asynchronously calls the server-side validation, and then in the callback apply the validation results to the field.

Thanks!
Joel