cancel
Showing results for 
Search instead for 
Did you mean: 

RadioButton, binding the selected

0 Kudos

Hello, In the data model it has an attribute called condition, it can return "AND" or "OR", based on that I have to select the correspondent radio button: Just to make it clear, if I was doing that with Select control, this would be the code: Now I want to do something similar with radiobutton, How Do I do that? help me, thanks.

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

ops... I dont know how to add source code here, so I removing the "<" and">"

I want to do this:

Select selectedKey="{newModel>/condition}"

  core:Item  key="AND" text="AND"/

  core:Item  key="OR" text="OR"/

/Select

but with radiobutton:

RadioButton  groupName="condition" text="AND"/

RadioButton  groupName="condition" text="OR" /

thanks.

kedarT
Active Contributor
0 Kudos

Hi Cristiano,

You could achieve this via Formatting, below is the code for AND radiobutton

Radiobutton = new sap.m.RadioButton({selected: {path: "Condition},

                                                                           formatter: function(val){

                                                                                if(condition == 'AND')

                                                                                         return true;

                                                                                     }else{ return false}

Hope this helps.

0 Kudos

Hi Kedar, the solution you gave me it works to display the information, but id does not work when I am saving the information.

the way it is, when the user edit and click on save, in the controller, before sending it to the backend, it still has to get the radio buttons and verify which one is selected and set "and/or" value into the mymodel>/condition.

I want the same behavior as the "select" example, I don't want to do extra steps in the controller, when saving it. thanks.

kedarT
Active Contributor
0 Kudos

Hi Cristiano,

Hope this helps - JS Bin - Collaborative JavaScript Debugging

I have used a JSON model to store the text of the RadioButton Selected and on hitting Save I am reading the same to fill in the Text. In your case we can read the JSON model and pass it into the oData model entity.