【问题标题】:flex4 - CheckBox and RadioButton validationflex4 - CheckBox 和 RadioButton 验证
【发布时间】:2014-03-21 10:16:38
【问题描述】:

在我的应用程序中,我有单选按钮和复选框。在这里,当我移动到下一个控件时,我想验证 CheckBox 和 RadioButton。

编辑:

我的代码在这里

<fx:Declarations>
    <s:RadioButtonGroup id="genderOption"/>

    <mx:StringValidator
        id="radioButtonValidator"
        source="{genderOption}"
        property="selectedValue"
        trigger="{groupLevel}"
        listener="{groupLevel}"
        required="true"
        requiredFieldError="field is required"/>

    <mx:StringValidator
        id="checkBoxValidation"
        source="qualificationGroup"
        required="true"
        property="selectedValue"
        listener="{qualificationGroup}"
        requiredFieldError="field is required"/>
</fx:Declarations>
<s:layout>
    <s:HorizontalLayout/>
</s:layout>

<mx:HDividedBox width="100%" height="100%">
    <s:Panel id="mainPanel" title="Employee Details" height="100%" width="50%">
        <s:Form id="mainForm" height="100%" width="100%" left="10%" right="10%" top="10%">
            <s:FormItem id="genderLabel" label="Gender" showErrorSkin="true" showErrorTip="false">              
                <s:HGroup id="groupLevel">
                    <s:RadioButton group="{genderOption}" label="Male" id="male" selected="false"/>
                    <s:RadioButton group="{genderOption}" label="Female" id="female" selected="false"/>
                </s:HGroup>
            </s:FormItem>
            <s:FormItem id="quaLabel" label="Qualification" showErrorSkin="true" showErrorTip="false">
                <s:HGroup id="qualificationGroup">
                    <s:CheckBox id="bsc" label="B.Sc"/>
                    <s:CheckBox id="be" label="BE"/>
                    <s:CheckBox id="mca" label="MCA"/>
                    <s:CheckBox id="mba" label="MBA"/>
                    <s:CheckBox id="others" label="Others"/>
                </s:HGroup>
            </s:FormItem>
        </s:Form>
    </s:Panel>  
</mx:HDividedBox>   

我是 flex 的新成员。如果我使用更改或单击事件,它将通过警报框显示错误消息。但我不想要警报框。还有其他显示错误信息的方法吗?

【问题讨论】:

  • 您能提供更多信息吗?如果您创建一个验证函数并在复选框和单选按钮发生更改时调用它(监听更改事件)
  • 请查看我的编辑,并帮助我。谢谢
  • 对不起,我没办法,我没有使用这个 mx 验证器的经验。2
  • 好的。谢谢你的答复。请看这个问题URL

标签: actionscript-3 apache-flex actionscript flex4


【解决方案1】:

当您移动到下一个控件添加和事件侦听器以调用函数来执行验证检查。

如果没有更多信息,我不能说哪个事件监听器适用,但它很可能是一个点击事件。

<Script>
<![CDATA[
    protected function validate_HDivide(event:MouseEvent):void
    {
        if(mycheckboxes.validate())
        {
            //do things
        }
        else
        {
            //display error
        }
    }
<s:HDividedBox id="mycheckboxes" change="validate_HDivide(event)"/>
<s:Button label="submit" click="validate_HDivide(event)"/>

然后在您的 HDividedBox 中,您可以进行验证

我就是这样做的,希望对你有所帮助。

【讨论】:

  • 我有按钮组。但是抱歉,我必须在哪里进行更改事件?请看我的编辑代码。
  • 我已根据您的编辑代码编辑了我的答案。抱歉,这可能不是最好的答案,因为我比较陌生
  • 但是当我从 HBox 更改控件时,我想这样做。
  • 对不起,我不明白你的意思,在你的代码中你没有改变 HBox 中的任何东西,你只是想检查我的解决方案允许的内容。
  • 在我的代码中,我还有一些其他组件。我想在 Change 事件发生时调用 validate_HDivide(event) 函数。
猜你喜欢
  • 2013-01-04
  • 2012-04-12
  • 1970-01-01
  • 1970-01-01
  • 2011-12-29
  • 1970-01-01
  • 2012-05-26
  • 2011-03-27
  • 2021-01-18
相关资源
最近更新 更多