Skip to Content

SAP UI5 radio button group data binding

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 .

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    Aug 27, 2018 at 01:15 AM

    make it (

    textType

    ) boolean

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

    Add comment
    10|10000 characters needed characters exceeded

    • 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?

  • Aug 24, 2018 at 05:58 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 26, 2018 at 12:25 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 27, 2018 at 12:04 AM

    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}===''}" />
    Add comment
    10|10000 characters needed characters exceeded