Tag Archives: Actionscript

Reset validation in Flex

Random code snippet time…

In Flex it’s very common to run validation on a form field before submitting – from ensuring a field isn’t empty to checking a phone number or email address is correctly formatted. Generally if validation fails you get a red border and some hover text derived from the component’s errorString field.

Resetting a validation result is less straightforward. The internet is full of this answer:

textfield.errorString = "";

At first glance this seems to work, but future validation fails, since all you’ve done is clear the error message, not clear the validation status. What you need to do is to actually set the validation status to OK:

textfield.dispatchEvent(new ValidationResultEvent(ValidationResultEvent.VALID));

Et voilà. Clear and repeatable.