RadioButton functionality in custom component

耗尽温柔 提交于 2019-12-11 15:00:11

问题


I am trying to create an xmxl component which contains an image and a radio button. The main application script will use several of these components.

I am having problems trying to get the RadioGroup to function properly. I have binded a variable on the RadioButton groupName attribute in the component mxml file so I can set this in the main application script.

This functions properly as when I tab through each RadioGroup, only the first radiobutton of each group gets the focus. But when I click each radio button in a group, the previous one does not deselect.

I have read that I cannot bind component id's so how else can I achieve selecting only one radio button in each group? Do I need to implement IFocusManager?

Thank You


回答1:


Each group of RadioButtons needs a RadioButtonGroup assigned to the groupName. The RadioButtonGroup makes sure only 1 button is selected at a time. The RadioButtonGroup is declared in <fx:Declarations> and is the name of the RadioButtonGroup is assigned in the groupName property.

    <fx:Declarations>
        <s:RadioButtonGroup id="paymentType" itemClick="handlePayment(event);"/>
    </fx:Declarations>
    <s:VGroup paddingLeft="10" paddingTop="10">
        <s:RadioButton groupName="paymentType" 
                       id="payCheck" 
                       value="check" 
                       label="Pay by check" 
                       width="150"/>
        <s:RadioButton groupName="paymentType" 
                       id="payCredit" 
                       value="credit" 
                       label="Pay by credit card" 
                       width="150"/>
    </s:VGroup>

The Apache Flex reference: http://flex.apache.org/asdoc/spark/components/RadioButtonGroup.html



来源:https://stackoverflow.com/questions/48019595/radiobutton-functionality-in-custom-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!