问题
Reproduce problem:
- run code
- click checkbox
- click on the first input box
- enter: 100
The red glowing error box should have disappeared, but it will disappear when you focus on another component e.g. the second input box.
If you refersh the screen, click the checkbox, and TAB onto the first input box, type 100, the error glow will disappear as I expected. This is what I want for click also. Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
initialize="onInit()">
<mx:Script>
<![CDATA[
import mx.validators.NumberValidator;
private var amountValidator:NumberValidator;
private function onInit():void{
amountValidator = new NumberValidator();
amountValidator.property = "text";
amountValidator.trigger = txtAmount;
amountValidator.triggerEvent = "change";
amountValidator.minValue = 10;
amountValidator.domain = "int";
amountValidator.precision = 0;
amountValidator.allowNegative = false;
amountValidator.source = txtAmount;
}
private function onInputChange():void{
amountValidator.validate();
trace("input");
}
private function checkClick():void{
if(myCheckBox.selected){
amountValidator.validate();
}
}
]]>
</mx:Script>
<mx:HBox horizontalGap="5" x="68" y="37">
<mx:CheckBox id="myCheckBox" click="checkClick()"/>
<mx:TextInput id="txtAmount" change="onInputChange()" width="160" height="20" restrict="0-9" maxChars="8" x="75" y="44"/>
<mx:TextInput id="dummyInput" y="72" x="75"/>
</mx:HBox>
</mx:Application>
回答1:
Lovely stuff, found an answer to this question at last.
It is logged as a bug under Flex SDK 3.5 with a workaround. Add a keyUp event tag to the target TextInput component as follows:
keyUp="txtAmount.drawFocus(true)"
Bingo!
来源:https://stackoverflow.com/questions/4564815/flex-number-validation-wont-remove-red-glow-if-click-focus-example-provided