flex4 - 复选框和单选按钮验证



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

编辑:

我的编码在这里

<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>   

我是弹性的新人。如果我正在使用更改或单击事件,它将通过警报框显示错误消息。但我不想要警报框。有没有其他方法可以显示错误消息?

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

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

<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中,您可以进行验证

这就是我会做的,希望这有帮助。

最新更新