2

I have a view ..

<mvc:View controllerName="quiz.controller.View1"
  xmlns:mvc="sap.ui.core.mvc"
  xmlns="sap.m"
  displayBlock="true"
>
  <App>
    <Page title="{i18n>title}">
      <Text text="{questions>/question/text}" />
      <RadioButtonGroup columns="5">
        <RadioButton id="RB3-1" text="{questions>/question/option/1}" />
        <RadioButton id="RB3-2" text="{questions>/question/option/2}" />
        <RadioButton id="RB3-3" text="{questions>/question/option/3}" />
        <RadioButton id="RB3-4" text="{questions>/question/option/4}" />
      </RadioButtonGroup>
      <Button text="Default" press=".onPress" />
    </Page>
  </App>
</mvc:View>

.. in which there is a radio button group with four options. I was looking to display one of the radio buttons as selected as soon as the button is pressed.

sap.ui.define([
  "sap/ui/core/mvc/Controller",
  "sap/m/MessageToast"
], function(Controller, MessageToast) {
  "use strict";

  return Controller.extend("quiz.controller.View1", {
    onPress: function(evt) {
      // MessageToast.show(); over here I want to show the button which is pressed
    }
  });
});

How do I do it? I tried by using document.getElementById() but it's not working here.

1 Answer 1

2

You need to give id to:

<RadioButtonGroup id="IDRadioButtonGroup" 

and access it in the button method:

onPress:  function(){
   var oIDRadioButtonGroup = this.byId("IDRadioButtonGroup");
   console.log("BUTTON: " + oIDRadioButtonGroup.getSelectedButton());
}

Here is example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.