Hi,
In saveData, you trust on the return value of validate. With asynchronous
validation, however, the return value is always falsy. Thats because at the
time the result of the validation is still unknown. Listen to the managers
"complete" event instead.
What I noticed is that you are wrapping a synchronous request in a timeout
(asynchronous, obviously). If you make a synchronous request (better not!),
there is no point in using the AsyncValidator.
In the function you pass to the AsyncValidator, instead of:
window.setTimeout(function() {
req.setAsynchronous(false);
req.send();
});
I recommend you just do:
// Request is asynchronous by default
req.send()
and call the validators setValid method in the listener for the "completed"
event (as before).
Am 11.10.2011 um 15:48 schrieb smisobnline:
> 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
------------------------------------------------------------------------------
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