Flex - number validation, wont remove red glow if click focus? (example provided)

浪尽此生 提交于 2019-12-24 12:53:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!