A typical way to validate a combobox is to validate the index to ensure
someone has selected a value. To do this, create a NumberValidator
instance like this:
 
 <mx:NumberValidator id="myComboValidator" source="{validateAssignee}"
lowerThanMinError=""
        property="selectedIndex" minValue="1" required="true" />

Note that lowerThanMinError String property must be empty.
 
Then, at some point post creation, set the lowerThanMinError to the text
you wish to show the user when they hover the control if it fails
validation. Where I find this most useful is if you have a Commit or
Save button on your form, in the handler for that action, set the error
message text:
 
validateAssignee.lowerThanMinError = "Assignee is required";
 
And then, run the validation on all your validator collection:
 
if (Validator.validateAll(validators).length != 0)
{
   // put up a message that one or more fields failed validation; they
will have red outlines
}
 
This is just one approach I found to work around the fact that ComboBox
always initializes to a red outline when using validator.
 
My guess to the root cause is that you're setting the
ComboBox.selectedIndex or are binding to selectedItem which will cause
the validation to execute. 
 
Another possible solution is to set required="false" initially and then
set it to "true" later on, after the selectedIndex or selectedItem has
been initialized.
 
Erik

________________________________

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of b.kotireddy
Sent: Thursday, January 15, 2009 12:28 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: How to avoid red borders created by validators
at page loading



Hi,

Could any one tell me what is the better way to validate a Combo Box.
Please post me some sample code or reference please

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
, "b.kotireddy" <koti_reddy...@...>
wrote:
>
> Hi,
> 
> In my page i have textInput's and Combo Box fields. When my page loads
> Text Input fields are not having any red borders, but all Combo Boxes
> are with red borders with "This Field is required". I think these
> because of Validations. Is their any way that i can avoid that red
> borders with text. 
> 
> Thanks in Advance
> koti
>



 

Reply via email to