簡體   English   中英

flex4-CheckBox和RadioButton驗證

[英]flex4 - CheckBox and RadioButton validation

在我的應用程序中,我同時具有單選按鈕和復選框。 在這里,當我移至下一個控制時,我想同時驗證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的新人。 如果我使用更改或單擊事件,它將通過警報框顯示錯誤消息。 但我不要警報框。 還有其他顯示錯誤消息的方法嗎?

當您移至下一個控件時,添加和事件偵聽器以調用函數以執行驗證檢查。

沒有更多信息,我不能說哪個事件偵聽器將適用,但是很可能是單擊事件。

<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中,您可以執行驗證

那就是我會怎么做,希望能有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM