Skip to Content

Clear RadioButtonGroup selection

Hi All,

is there a way to clear a RadioButtonGroup's selection? I want to have as result a group with no option selected.

Lets say I have a RadioButtonGroup with the first option selected. I want all selections to be cleared when I press a button.

Regards,

Szilamér

Add comment
10|10000 characters needed characters exceeded

2 Answers

  • Best Answer
    Posted on Dec 04, 2015 at 06:23 AM

    Yes, I agree with sai. Try this working example, It may be useful for you. 😊

    Will this help? http://jsbin.com/nivehemaya/edit?html,js,output

    @sai - Instead of adding len+1. we can try this rb.setSelectedIndex(null);

    Regards,

    Karthik A

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 03, 2015 at 02:53 PM

    Hi Szilamer,

    Try like this -

    var oRadioGroup = sap.ui.getCore().byId("yourRadioGrp");     //Get Hold of Radio Button Group
    oRadioGroup.setSelectedIndex(-1);
    
    
    

    But the above is available on/after 1.30 version: No default in RadioButtonGroup · Issue #588 · SAP/openui5 · GitHub

    If you are on lower version, a work around would be setting the value +1 to your radio buttons length. Something like -

    var oRadioGroup = sap.ui.getCore().byId("yourRadioGrp");      //Get Hold of Radio Button Group
    var oRadioButtons = oRadioGroup.getAggregation("buttons");          //For Mobile (sap.m)
    var oRadioButtons = oRadioGroup.getAggregation("items");          //For Desktop (sap.ui.commons)
    var oLength = oRadioButtons.length;
    oRadioGroup.setSelectedIndex(oLength+1);
    
    
    

    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded