如何验证单选按钮组?处于弯曲状态

发布于 2024-08-25 05:45:27 字数 70 浏览 7 评论 0原文

如何验证 Flex 3 中的单选按钮是否被选中?

如果我的问题是错误的,请向我提出有关无线电组验证的任何建议。

How to validate the radio button is selected or not in flex 3?

if my question is wrong, please suggest me any thing regarding the validation of radio group.

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

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

发布评论

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

评论(4

话少心凉 2024-09-01 05:45:27

只需使用 StringValidator:

        <mx:StringValidator id="myRadioButtonGroupValidator" 
        source="{myRadioButtonGroup}" 
        property="selectedValue" 
        required="true"/>

Simply use a StringValidator:

        <mx:StringValidator id="myRadioButtonGroupValidator" 
        source="{myRadioButtonGroup}" 
        property="selectedValue" 
        required="true"/>
姜生凉生 2024-09-01 05:45:27

对于 Spark 组和 RadioButtons,事情的工作方式略有不同。请参阅下面的示例。

注意:对于 HGroup,如示例所示:如果出现错误,将出现警告视线,但不会出现可见的红色边框。如果您将 RadioButton 本身设置为侦听器,您可能会得到一个丑陋的结果,如果您将 FormItem 设置为目标,您将看不到任何反应。

<fx:Declarations>

    <s:RadioButtonGroup id="myGroup" />

    <mx:StringValidator id="vLevel"
                        required="true"
                        source="{myGroup}"
                        property="selectedValue"
                        minLength="1"
                        maxLength="80"
                        listener="{grpLevel}"
                        />

</fx:Declarations>


<s:FormItem label="Level">
                <s:HGroup id="grpLevel">
                    <s:RadioButton group="{myGroup}" label="A"/>
                    <s:RadioButton group="{myGroup}" label="B"/>
                    <s:RadioButton group="{myGroup}" label="C"/>
                </s:HGroup>
</s:FormItem>                           

For Spark groups and RadioButtons things work slightly different. See the example below.

Note: For a HGroup as the example shows: The warning-sight will appear for errors but there will be no red-colored border be visible. If you set a RadioButton itself as listener you might get an ugly result and if you set a FormItem as target you will see nothing happen.

<fx:Declarations>

    <s:RadioButtonGroup id="myGroup" />

    <mx:StringValidator id="vLevel"
                        required="true"
                        source="{myGroup}"
                        property="selectedValue"
                        minLength="1"
                        maxLength="80"
                        listener="{grpLevel}"
                        />

</fx:Declarations>


<s:FormItem label="Level">
                <s:HGroup id="grpLevel">
                    <s:RadioButton group="{myGroup}" label="A"/>
                    <s:RadioButton group="{myGroup}" label="B"/>
                    <s:RadioButton group="{myGroup}" label="C"/>
                </s:HGroup>
</s:FormItem>                           
女中豪杰 2024-09-01 05:45:27

这就是我解决问题的方法。如果有什么不对的地方请留言评论。

<mx:NumberValidator id="radiogroupValidator" source="{radiogroup}" property="selectedValue" allowNegative="false" />

mxml 文件中的单选按钮组源

 <mx:RadioButtonGroup id="radiogroup"  itemClick="radiochangefunction(event)" selectedValue="-1" />

 <mx:RadioButton id="radiobtn1" groupName="radiogroup" label="Send Password to existing EmailId" value="0"/>
 <mx:RadioButton id="radiobtn2" groupName="radiogroup" label="Enter new EmailId" value="1"/>

itemClick 函数

public function radiochangefunction(event):void
{
   radiogroup.selectedValue=event.currentEvent.selectedValue.toString();     
}

以及最后的验证函数

var isValidradiobutton:Boolean = (Validator.validateAll([radiogroupValidator]).length==0);

This is the way I solved the problem. If anything is wrong please leave a the comment.

<mx:NumberValidator id="radiogroupValidator" source="{radiogroup}" property="selectedValue" allowNegative="false" />

radio group source in mxml file

 <mx:RadioButtonGroup id="radiogroup"  itemClick="radiochangefunction(event)" selectedValue="-1" />

 <mx:RadioButton id="radiobtn1" groupName="radiogroup" label="Send Password to existing EmailId" value="0"/>
 <mx:RadioButton id="radiobtn2" groupName="radiogroup" label="Enter new EmailId" value="1"/>

The itemClick function

public function radiochangefunction(event):void
{
   radiogroup.selectedValue=event.currentEvent.selectedValue.toString();     
}

and finally in validation function

var isValidradiobutton:Boolean = (Validator.validateAll([radiogroupValidator]).length==0);
不喜欢何必死缠烂打 2024-09-01 05:45:27

监听 RadioButtonGroupitemClick 事件。在处理程序中,使用 selectionselectedValue 属性来了解单击了哪个 RadioButton

  • selection - 返回对所选 RadioButton 实例的引用
  • selectedValue - 返回所选 value 属性RadioButton(如果已设置)。否则,返回其标签文本。

如果没有选择 RadioButton,这两个属性都会返回 null

来自 livedocs 的运行示例

<?xml version="1.0"?>
<!-- Simple example to demonstrate RadioButtonGroup control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[

        import mx.controls.Alert;
        import  mx.events.ItemClickEvent;

        // Event handler function to display the selected button
        // in an Alert control.
        private function handleCard(event:ItemClickEvent):void {
            if (event.currentTarget.selectedValue == "AmEx") {
                    Alert.show("You selected American Express") 
            } 
            else {
                if (event.currentTarget.selectedValue == "MC") {
                    Alert.show("You selected MasterCard") 
                } 
                else {
                    Alert.show("You selected Visa") 
                }
            } 
        }
        ]]>
    </mx:Script>

    <mx:Panel title="RadioButtonGroup Control Example" height="75%" width="75%" 
        paddingTop="10" paddingLeft="10">

        <mx:Label width="100%" color="blue" 
            text="Select a type of credit card."/>

        <mx:RadioButtonGroup id="cardtype" itemClick="handleCard(event);"/>
        <mx:RadioButton groupName="cardtype" id="americanExpress" value="AmEx" 
            label="American Express" width="150" />
        <mx:RadioButton groupName="cardtype" id="masterCard" value="MC" 
            label="MasterCard" width="150" />
        <mx:RadioButton groupName="cardtype" id="visa" value="Visa" 
            label="Visa" width="150" />

    </mx:Panel>        
</mx:Application>

Listen to the itemClick event of the RadioButtonGroup. Within the handler, use selection or selectedValue property to know which RadioButton was clicked.

  • selection - returns a reference to the selected RadioButton instance
  • selectedValue - returns the value property of the selected RadioButton, if it is set. Otherwise, returns its label text.

Both of these properties return null if no RadioButton is selected.

A running example from livedocs

<?xml version="1.0"?>
<!-- Simple example to demonstrate RadioButtonGroup control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[

        import mx.controls.Alert;
        import  mx.events.ItemClickEvent;

        // Event handler function to display the selected button
        // in an Alert control.
        private function handleCard(event:ItemClickEvent):void {
            if (event.currentTarget.selectedValue == "AmEx") {
                    Alert.show("You selected American Express") 
            } 
            else {
                if (event.currentTarget.selectedValue == "MC") {
                    Alert.show("You selected MasterCard") 
                } 
                else {
                    Alert.show("You selected Visa") 
                }
            } 
        }
        ]]>
    </mx:Script>

    <mx:Panel title="RadioButtonGroup Control Example" height="75%" width="75%" 
        paddingTop="10" paddingLeft="10">

        <mx:Label width="100%" color="blue" 
            text="Select a type of credit card."/>

        <mx:RadioButtonGroup id="cardtype" itemClick="handleCard(event);"/>
        <mx:RadioButton groupName="cardtype" id="americanExpress" value="AmEx" 
            label="American Express" width="150" />
        <mx:RadioButton groupName="cardtype" id="masterCard" value="MC" 
            label="MasterCard" width="150" />
        <mx:RadioButton groupName="cardtype" id="visa" value="Visa" 
            label="Visa" width="150" />

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