
170 Additional Migration Issues
Validators
In Flex 1.5, validators were usually triggered in response to an update of the destination of a
data binding expression. You typically assigned the validator to the destination of a data
binding expression, and triggered the validation when the destination of the data binding
expression was updated, as the following example shows:
<!-- Define a data model for storing the phone number. -->
<mx:Model id="userInfo">
<phoneNum>{phoneInput.text}</phoneNum>
</mx:Model>
<!-- Define the PhoneNumberValidator. -->
<mx:PhoneNumberValidator field="userInfo.phoneNum"/>
<!-- Define the TextInput control for entering the phone number. -->
<mx:TextInput id="phoneInput"/>
In Flex 2, validators are triggered by default by the valueCommit event, and you use data
binding to assign it to the interface control rather than to a model. The source property
specifies the name of the control, and the
property property specifies the field of the control
to validate, as the following example shows:
<!-- Define the PhoneNumberValidator. -->
<mx:PhoneNumberValidator id="pnV" source="{phoneInput}" property="text" />
<!-- Define the TextInput control for entering the phone number. -->
<mx:TextInput id="phoneInput"/>
You can also use the validate() method of the validator to trigger a validator
programmatically. All validator classes now include a
validate() method.
CreaditCardValidator constants moved to a new class
The constants that define the type of credit card to validate were moved from the
CreditCardValidator class to a new class named CreditCardValidatorCardType.
The constants were also renamed. In MXML, valid constants values are:
■ "American Express"
■ "Diners Club"
■ "Discover"
■ "MasterCard"
■ "Visa"
Kommentare zu diesen Handbüchern