I do not understand javascript behavior.
I am doing a jquery ui dialog form validation. This seems to be a javascript issue, not a jQuery issue.
To check, I execute a function for fields that return true or false, and a boolean variable gets the result of the sequential && & operator. Like this:
bValid = checkRegexp(validite, /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/, "Entrez la date de validit\350 sous la forme JJ/MM/AAAA." ); bValid = bValid && checkLength(libelle, "Libell\351", 1, 100 ); bvalid = bValid && checkLength(description, "Description", 1, 250);
Here, for information, check functions:
function checkLength( o, n, min, max ) { if ( o.val().length > max || o.val().length < min ) { o.addClass( "ui-state-error" ); if(o.val().length == 0) { textError = textError + "le champ " + n + " est requis !\n"; } else { textError = textError + "Taille de " + n + " entre " + min + " et " + max + "caract\350res.\n"; } return false; } else { return true; } } function checkRegexp( o, regexp, n ) { if (!(regexp.test(o.val()))) { o.addClass( "ui-state-error" ); textError = textError + n + "\n"; return false; } else { return true; } }
It is expected that all functions will be executed, and all invalid fields will be marked incorrectly when concatenating error messages. For information, the bValid variable contains the logical result of sequential && operators. This last point works; no problems.
The real behavior is that when a function returns false , the following functions do not seem to be executed. As a result, only the first incorrect field is encountered.
Why?