cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUi5 Radio Button Selected Text

0 Kudos

Dear SAPUi5 Experts

I have a radio button in my XMLview as shown below. The data is bound from the model. My requirement is to validate the radio buttons after the data binding. Below is my controller code. i am trying to read the value of the selectedButton text in my controllers AfterRendering method.

XML View: <RadioButtonGroup id="rbgtype" > <RadioButton text="Yes" selected="{/rbgtype}"/> <RadioButton text="No" selected="{=!${/rbgtype}}"/></RadioButtonGroup>

Controller onAfterRendering: function () { var that = this; console.log("rbgtype"+that.getView().byId("rbgtype").getSelectedButton().getText());} 

Strangely I am always getting the value "Yes" only irrespective of selected value. Can some one advise where I am doing wrong please.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

fixed by changing the view

<RadioButtonGroup id="rbgtype" selectedIndex ="{= ${/rbgtype} ? 0 : 1 }" editable="false">  
<RadioButton text="Yes" /> <RadioButton text="No"/>
</RadioButtonGroup>

Answers (2)

Answers (2)

ericci
Active Contributor

Hi Rio,

the problem is that you're using the wrong hook event to check the binding value. As far as I know there's no real event "bindingValueUpdated" so what you could do is to listen to the setSelected (overriding it) and wait for it.

maheshpalavalli
Active Contributor

It may be due to the reason that binding has not applied to the radio button immediately after rendering. I would recommend you to validate after the data is received in the model.

If you are reading manually then simply in the success handler you can perform the check which would be better.