ErrorInputField
| Kind of class: | class |
|---|---|
| Inherits from: | HintedInputField < InputField < EventMovieClip < MovieClip |
| Classpath: | org.asapframework.ui.input.ErrorInputField |
| File last modified: | Tuesday, 07 November 2006, 16:02:05 |
Class to be used for text input in forms with validation.
Attach this class to a movieclip containing the following:
Attach this class to a movieclip containing the following:
- a textfield named "input_txt"
- two frames with labels "ok" & "error"
- some visible distinction between the content on the two labels, p.e. a red border or background on the "error" label that isn't there on the "ok" label
Example:
- This example shows how to initialize and perform validation and feedback.
Assume three ErrorInputField instance are present on the timeline, named "title_mc", "name_mc" & "email_mc".
Before posting the form, the fields are validated. The title & name will have to be non-empty, the email is checked for valid structure.class Form extends MovieClip { private var mValidator:Validator; private var mInputFields:Array; // all ErrorInputField instances private function onLoad () : Void { var timeline:MovieClip = MovieClip(this); // retrieve input fields from the timeline var titleField:ErrorInputField = ErrorInputField(timeline.title_mc); var nameField:ErrorInputField = ErrorInputField(timeline.name_mc); var emailField:ErrorInputField = ErrorInputField(timeline.email_mc); // store input fields in list mInputFields = [titleField, nameField, emailField]; // create validator mValidator = new Validator(); // add specific field validation mValidator.addValidation(new StringValidator(nameField)); mValidator.addValidation(new StringValidator(titleField)); mValidator.addValidation(new EmailValidator(emailField)); } private function validate () : Void { // hide errors on input fields var len:Number = mInputFields.length; for (var i : Number = 0; i < len; i++) { ErrorInputField(mInputFields[i]).showError(false); } // do validation var result:ValidationResult = mValidator.validate(); if (!result.success) { // loop through errors for (var i:Number=0; i<result.errors.length; ++i) { var error:ValidationError = ValidationError(result.errors[i]); // show visible error on input field if (error.target instanceof ErrorInputField) { ErrorInputField(error.target).showError(true); } } } } }
Summary
Constructor
Class properties
- OK_FRAME : String
- ERROR_FRAME : String
Instance properties
- mText : String
Instance properties inherited from HintedInputField
Instance properties inherited from InputField
Instance properties inherited from EventMovieClip
Instance methods
- showError (inError:Boolean) : Void
- Show textfield in 'error' or 'ok' state
- updateTextField : Void
Instance methods inherited from HintedInputField
Instance methods inherited from InputField
Event handlers
Event handlers inherited from HintedInputField
Event handlers inherited from InputField
Constructor
ErrorInputField
function ErrorInputField (
)
Constructor
Class properties
ERROR_FRAME
static private ERROR_FRAME:String = "error"
(read)
OK_FRAME
static private OK_FRAME:String = "ok"
(read)
Instance properties
mText
private mText:String
(read)
Instance methods
showError
function showError (
inError:Boolean) : Void
Show textfield in 'error' or 'ok' state
Parameters:
inError:
if true, the error state (frame labeled "error") will be shown; otherwise frame labeled "ok" will be shown
updateTextField
private function updateTextField (
) : Void