Flex has a great validation framework so the users that interect with the application can increase thier user experience.You can use the builtin flex validators (credit card, date, email, number, string, phone ...), use the valueCommitted event, use the Flex Validators or create custom and very powerful validation.
Working in a Rich Form application we faced with these tecnique and as a actionscript programmer i found more rapid and useful use class and function developer in AS :)
So i thought to share some of the tecnique used for this application about validating a form.
Let's start with the CAP (the italian for Zip Code) validation :
First i tried to use the Flex builtin Zip Code Validator class :
The ZipCodeValidator class validates that a string has the correct length for a five-digit ZIP code or a five-digit+four-digit United States ZIP code or Canadian postal code.
I found the domain property to select the type of zip code to validate :
domain : The type of ZIP codes to check. Permitted values are "US Only" and "US or Canada". The default value is "US Only".
This is a simple example of using the class :
But for italian Zip code it did not work. So i tried to use the NumberValidator class in this way :
I customized all the error messages in italian language.
But i gettin in trouble with this class, so i finally decided to use a custom actionscript function :)
This is an abstract of the function :
function Valida (validator, value) : Void
{
// Check for the lenght
if (value.cap.length != 5) {
validator.validationError("campoMancante", "Devi inserire un valore valido per il campo CAP", null);
return;
}
// Check for is a number value
if (isNaN(value.cap)) {
validator.validationError("campoMancante", "Devi inserire un valore valido per il campo CAP", null);
return;
}
}
This function is triggered by a click event that launches the isValid method :
where fatturazioneModel is my data Model :
{sociale.text}
{iva.text}
{via.text}
{civico.text}
{cap.text}
{citta.text}
{provincia.text}
{telefono.text}
{fax.text}
{email.text}
{pagamenti.selectedData}
Next i'll speak about other tecnique used for a rich form application !
Wait for comments :)