cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 radio button group data binding

0 Kudos

Dear SAP UI5 experts,

can some one please advise on the two-way data binding of the radio buttons . In the data model I have an attribute called textType, it can return "Y" or "N", based on that I have to select the correspondent radio button on my view

<code><m:RadioButtontext="yes"selected="{path:'/textType',formatter: function(val){ if(textType== 'Y') return true; }else{ return false} }"/><m:RadioButtontext="No"selected="{Selected}"/>


however I am not able to set the value. I tried using the radiobutton group however no success

<code><RadioButtonGroupbuttons="{/textType}"><RadioButtontext="YES"selected="{Selected}"/><RadioButtontext="No"selected="{Selected}"/></RadioButtonGroup>


can some one pls advise on this .

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

make it (

textType

) boolean

once you use format function, it becomes oneway binding, model data will go to screen but not vice versa

0 Kudos

Hi Jun,

have tried changing it to Boolean and in my view change it to

.... <m:RadioButton text="Yes" selected ="{Text_Type}" />

however I am not able to get the data displayed any other input?

Answers (3)

Answers (3)

maheshpalavalli
Active Contributor

the path in the selected property is given as "{selected}", I think it should be "/selected" ( assuming it is direct property binding and not originated from element binding) and It should work as I've tried it some time back.

Note: one more thing is if you put the formatter it will become one way binding, not two way, I guess you have to check that as well

Formatter functions allow one-way conversion only, while data types can also be used for two-way binding as they cannot only format, but also parse user input

junwu
Active Contributor

the easy way is to make the field type to boolean, or you have to use custom data type in binding.

0 Kudos

Yes Jun, I have used field type as Boolean.

0 Kudos

Yes I have used expression binding as I need this to save the data as well to the backend.
<m:RadioButton text="YES" selected ="{= ${/textType}==='YES'}" />  <m:RadioButton text="No" selected = "{=${/textType}===''}" />