MX. validators. The default error message "validator" indicates that the English text is really nice, but the effect is too bad when the Chinese text is displayed. It cannot be seen clearly and is bold. Because MX. validators. validator does not directly provide the method attribute of the style application, the following method is to use stylemanager to modify the error display effect:
Content of the test. mxml file:
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.macromedia.com/2003/mxml"
Xmlns = "*" verticalgap = "0">
<Mx: SCRIPT>
<! [CDATA [
Import MX. Styles. stylemanager;
Function changenormal (){
Stylemanager. Styles. errortip. fontweight = "nomal ";
Stylemanager. Styles. errortip. fontfamily = "Arial ";
Stylemanager. Styles. errortip. fontsize = "9 ";
VaR S1 = stylemanager. Styles. errortip. getstyle ("fontweight ");
Address. Text = S1;
}
Function changebold (){
Stylemanager. Styles. errortip. fontweight = "bold ";
Stylemanager. Styles. errortip. fontfamily = "Helvetica ";
Stylemanager. Styles. errortip. fontsize = "15 ";
VaR S1 = stylemanager. Styles. errortip. getstyle ("fontweight ");
Address. Text = S1;
}
]>
</MX: SCRIPT>
<Mx: Model id = "order">
<Name> {name. Text} </Name>
<Address> {address. Text} </address>
<City> {city. Text} </city>
<Zip> {zip. Text} </zip>
<Email> {email. Text} </Email>
</MX: Model>
<Requiredfieldvalidator field = "order. Name"/>
<Requiredfieldvalidator field = "order. City"/>
<Mx: emailvalidator field = "order. Email"/>
<Mx: Form>
<Mx: formitem label = "name" required = "true">
<Mx: Text text = "the following characters are entered: 1 indicates an error message"/>
<Mx: textinput id = "name" width = "200" type = "codeph" text = "/codeph"/>
</MX: formitem>
<Mx: formitem label = "Address">
<Mx: textinput id = "Address" width = "200" type = "codeph" text = "/codeph"/>
</MX: formitem>
<Mx: formitem label = "city" required = "true">
<Mx: textinput id = "city" width = "200"/>
</MX: formitem>
<Mx: formitem label = "Zip" required = "true">
<Mx: textinput id = "Zip" width = "100"/>
</MX: formitem>
<Mx: formitem label = "email" required = "true">
<Mx: textinput id = "email" width = "200"/>
</MX: formitem>
</MX: Form>
<Mx: hbox>
<Mx: button label = "general display" Click = "changenormal ()"/>
<Mx: button label = "bold" Click = "changebold ()"/>
</MX: hbox>
</MX: Application>
Requiredfieldvalidator. As file content:
Class requiredfieldvalidator extends MX. validators. validator {
Function dovalidation (value): void {
If (value = "1" | value = NULL ){
Validationerror ("required", "Enter the name", "123 ");
}
If (value = "2 "){
Validationerror ("required", "error ");
}
}
}