Hello , i want to validate a username . i use the code below to
validate. i have some problems
1. the validate message
validator.setInvalidMessage("Mindestens 5 Buchstaben.")
dosent appear, but the field is marked as error
2. the validate check is everytime false, beause , i think, at the time
the validation is checked, the ajax request isnt finished. how can i fix
this?
here is the code
i add a validatoor like this
addValidator : function() {
this.formManager = new
qx.ui.form.validation.Manager();// create the form manager
// Textlength
var textLengthValidator = function(value, item) {
var minLength = 3;
var valid = value != null && value.length >= minLength;
if (!valid) {
item.setInvalidMessage("Mindestens " +
minLength + " Zeichen.");
}
return valid;
};
// Time Validator
var timeValidator = function(value, item) {
var valid = value.charAt(2) == ":" && value.length
== 5;
if (!valid) {
item.setInvalidMessage("Zeit im Format 00:00.");
}
return valid;
};
var USERID = this.USERID;
this.formManager.add(this.widgets["username"], new
qx.ui.form.validation.AsyncValidator(
function(validator, value) {
// here comes the async call
window.setTimeout(function() {
// callback for the async validation
try {
var req = new
qx.io.remote.Request(makebiz.system.Globals.processorURL, "POST",
"application/json");
req.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
req.setAsynchronous(false);
req.setTimeout(30000);
req.setParameter("m" ,
"userverwaltung");
req.setParameter("c" ,
"checkDuplicateUsername");
req.setParameter("USERID" , USERID);
req.setParameter("username" , value);
req.addListener("completed", function(e) {
var j = e.getContent();
if(value.length < 5) {
validator.setValid(false);
validator.setInvalidMessage("Mindestens 5 Buchstaben.")
return false;
}
else if(j["data"]["isduplicate"] ==
false) {
validator.setValid(true);
return true;
}
else {
validator.setValid(false);
validator.setInvalidMessage("Der Username ist bereits vergeben.")
return false;
}
},this);
req.addListener("timeout", function(e) {
var j = e.getContent();
alert("Timeout Error: "+ j);
},this);
req.send(); // Send Request
}
catch (ex) {
alert("Verbindungsprobleme mit dem
Server: " + ex.toString());
}
}, 1000);
}
));
this.formManager.add(this.widgets["vorname"],
textLengthValidator);
this.formManager.add(this.widgets["nachname"],
textLengthValidator);
this.formManager.add(this.widgets["password"],
textLengthValidator);
},
and use it like this
saveData : function(){
if(this.formManager.validate()) {
alert("ok");
}
}
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel