Search code examples
sapui5

Make Selected Radio Button Text Bold (UI5)


I am using RadioButton Group in UI5, and my requirement is to make the selected radio button text 'Bold'. Can this be achieved by css or Formatter. Thanks

.......code snippet......

"": {
    "prefix": "",
    "body": [
        "RadioButtonGroup buttons=\"{oModelSummary>/QuestionSet}\" selectedIndex=\"{oModelSumnary>selectedIn}\" select=\"onSelectRb\" enabled=\"false\">",
        "<buttons>",
        "<RadioButton text=\"{oModelSummary>Name}, formatter:'MyformatterPath'\"/>",
        "</buttons>",
        "</RadioButtonGroup>"
    ],
    "description": ""
}

Solution

  • Add a select event listener to the radiobuttongroup and add a css class to the selected control:

    onSelectRadioButtonGroupOption: function (oEvent) {
        var aRadioButtons = oEvent.getSource().getButtons();
        // Remove bold from all radiobuttons
        aRadioButtons.forEach(function (oButton) {
            oButton.removeStyleClass("your-bold-css-class");
        });
        // Add bold class to selected radiobutton
        var nSelectedIndex = oEvent.getParameter("selectedIndex");
        aRadioButtons[nSelectedIndex].addStyleClass("your-bold-css-class")
    }