警报被多次触发

发布于 2024-11-28 16:23:16 字数 2079 浏览 0 评论 0原文

以下代码按以下方式工作:

当我在 txtother.textbox 中输入不正确的值并聚焦时,警报将显示为“请输入有效的格式掩码。” . 按警报框中的“ok”按钮后,txtOther.focusout 事件会再次触发。 即按下警报的OK后,立即再次显示相同的ALERT

我已经添加了代码供您参考:

//in mxml File:
<mx:Canvas label="General" >
<mx:VBox>
<mx:Canvas id="cvsGeneral"> 
<mx:TextInput id="txtOther" focusOut="txtOther_Validate();"/>
</mx:Canvas>
</mx:VBox>                              
</mx:Canvas>

<mx:Canvas width="100%" height="5%" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:HBox width="80%" height="100%" horizontalAlign="left">
<mx:Button width="64" label="Save" id="btnSave" click="btnSave_Click();" focusIn="txtOther_Validate();"/>
</mx:HBox>
</mx:Canvas>


//Validating action script is as follows:
public function txtOther_Validate():void{
    var formatMask: String = null;  
        if(txtOther.editable && txtOther.enabled){
            if(txtOther.text != ""){
                formatMask = txtOther.text;
                if(conditions to validate){
                    //some expression
                }               
                if(formatMask.length < 12){
                    Alert.show("Please enter format mask with minimum 12 digits.");
                    txtOther.setFocus();
                    return;
                }               VariableEditControl.getInstance().validateFormatMask(txtOther.text,validateFormatMask_Result,validateFormatMask_Fault, validateFormatMask_Error);
            }
        }   
}
public function validateFormatMask_Result(event:PLEvent): void {
    var result:String = event.getData().toString(); // here lets assume that the result variable is stored as "FAILURE"
    if(result == "FAILURE"){
        Alert.show("Please enter a valid Format Mask.");
        txtOther.setFocus(); //
    }
}

我不想警报一次又一次出现.. 我需要它,当按下警报的确定按钮时。 txtother.text 应该处于焦点位置,并且警报不应像以前一样一次又一次出现。

The following code works in the following way:

When I enter incorrect values in the txtother.textbox and focuses out, an alert will be displayed as "Please enter a valid Format Mask." .
After pressing the "ok" button in the Alertbox the txtOther.focusout even is triggered again.
i.e. immediately after pressing the OK of alert, the same ALERT is displayed again.

I have added the code for ur reference:

//in mxml File:
<mx:Canvas label="General" >
<mx:VBox>
<mx:Canvas id="cvsGeneral"> 
<mx:TextInput id="txtOther" focusOut="txtOther_Validate();"/>
</mx:Canvas>
</mx:VBox>                              
</mx:Canvas>

<mx:Canvas width="100%" height="5%" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:HBox width="80%" height="100%" horizontalAlign="left">
<mx:Button width="64" label="Save" id="btnSave" click="btnSave_Click();" focusIn="txtOther_Validate();"/>
</mx:HBox>
</mx:Canvas>


//Validating action script is as follows:
public function txtOther_Validate():void{
    var formatMask: String = null;  
        if(txtOther.editable && txtOther.enabled){
            if(txtOther.text != ""){
                formatMask = txtOther.text;
                if(conditions to validate){
                    //some expression
                }               
                if(formatMask.length < 12){
                    Alert.show("Please enter format mask with minimum 12 digits.");
                    txtOther.setFocus();
                    return;
                }               VariableEditControl.getInstance().validateFormatMask(txtOther.text,validateFormatMask_Result,validateFormatMask_Fault, validateFormatMask_Error);
            }
        }   
}
public function validateFormatMask_Result(event:PLEvent): void {
    var result:String = event.getData().toString(); // here lets assume that the result variable is stored as "FAILURE"
    if(result == "FAILURE"){
        Alert.show("Please enter a valid Format Mask.");
        txtOther.setFocus(); //
    }
}

I don't want to the alert to come again and again ..
I need it in such a way that when the ok button of alert is pressed. The txtother.text should be in focus, and the alert should not come again and again as before.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暖阳 2024-12-05 16:23:16

这是因为您再次点击“确定”按钮上的 focusIn="txtOther_Validate();" 。只需删除 focusIn 处理程序就可以了。

it's because you have the focusIn="txtOther_Validate();" on the ok button a second time. just remove the focusIn handler and you should be fine.

听,心雨的声音 2024-12-05 16:23:16

我可能有误,但我认为警报框不会等到您关闭它。因此,您触发验证并立即将焦点设置回输入。现在,您单击警报框的“确定”按钮,这将使输入失去焦点,从而触发验证,从而引发警报……等等。

I may be in error but I think the alert box won't wait till you close it. So you trigger your validate and immediately set the focus back to the input. Now you click the alert box's ok button which will make the input lose the focus triggering the validation which will raise the alert which will... and so on.

话少心凉 2024-12-05 16:23:16

编辑:

stage.focus = txtOther;

这将在as3中工作...我不知道flex。

EDIT:

stage.focus = txtOther;

This will works in as3... I don't know about flex.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文