on 09-11-2018 11:48 PM
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.
fixed by changing the view
<RadioButtonGroup id="rbgtype" selectedIndex ="{= ${/rbgtype} ? 0 : 1 }" editable="false">
<RadioButton text="Yes" /> <RadioButton text="No"/>
</RadioButtonGroup>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.