Strange behavior with input validation

Hi,

I have a strange behavior with a input validation using my own rule. The validation is set in the object constructor with

{type:"password", name:"t1_password", label:"Password", validate:"checkpassword"},

and additionell with

mytab1form.setRequired("t1_password",true); .

The required rule works fine. My checkpassword method also work fine (if I try outside a validation)

[code] function checkpassword (password) {
if (password == “”) {
return true;
} else {
var link = “/4DCGI/GET_APPROVALS?SID=anyIDhere&FLAG=-99&ID=”+mytab1form.getItemValue(‘t1_responsible’);

window.dhx4.ajax.get(link, function(data){
 var xml = data.xmlDoc.responseXML;

 if (xml != null) {
   var root = xml.getElementsByTagName("root")[0];
   var mypw = root.getAttribute("id");

   if(calcMD5(mytab1form.getItemValue('t1_password')) == mypw) {

alert(“PW OK”);
return true;
} else {
alert(“2”);
return false;
}
} else {
alert(“1”);
return false;
}
});
}
}[/code]

But onValidateError fires each time I validate my form with mytab1form.validate(). The strange effect is onValidateError fires before alert(“PW OK”) comes up up. Could it be that the AJAX call in the validation rules is the problem??

Hi

That’s happend due async request actually your function returns undefined (rigth after get call) that’s why you first see onValidateError, then callback fired and you see alert(pwdok).

Try to replace window.dhx4.ajax.get -> window.dhx4.ajax.getSync (but sync load will froze page while response come from server). Also code for getSync a bit different, please check here docs.dhtmlx.com/api__dhtmlxajax_getsync.html