Skip to Content

Retrieve the Key value of a sap.m.RadioButtonGroup (xml view) / oData Model

Hello Experts,

My challenge is to retrieve the Key value of a RBG in a Fiori app linked to an oData Service. From a Previous question I have obtained this answer: http://jsbin.com/hanadofuco/1/edit?js,output and it works fine in the json Model.

in my view.xml:

<RadioButtonGroup xmlns="sap.m"
id="Stoff"
Buttons="{/ZUI5_TEST_TVALUES_SET}"
width="500px"
class="sapUiMediumMarginBottom"
select="onSelectRadio">
<RadioButton text="{ATWTB}" key="{ATWRT}"/>
</RadioButtonGroup>

and the function in controller:

onSelectRadio: function(oEvent) {
var oSelectedIndex = oEvent.getParameter("selectedIndex");
var oModelo = this.getView().getModel();
var sKey  = oModelo.getProperty("/ZUI5_TEST_TVALUES_SET/"+oSelectedIndex+"/ATWRT");
  },

After getting the Model in "oModelo"  (image from Debugger below), "Skey" still results in "undefined".

How can I obtain in this case the ATWRT value? (Key value) or this sap.m.RadioButtonGroup?

Thank you

PD I was able to retrieve the text value of a RBG (thanks to this post->) But now the question is about key value.

pastedImage_19.png (67.6 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 27, 2015 at 03:45 PM

    You can fetch the bindingContext from the instance of the selected item and get the data from the context.

    onSelectRadio: function(oEvent) {
        var oSource = oEvent.getSource();
        var oContext = oSource.getSelectedButton().getBindingContext();
        var oData = oContext..getObject();
        console.log(oData.ATWRT);
    }
    
    Add comment
    10|10000 characters needed characters exceeded

    • Hello Saktivel,

      The variable oData will contain all the properties of the selected Item you are right. The property ATWTB is not the key, but the name of the Item. The key value is ATWRT and that makes your solution correct.

      Best Regards,

      Gabriel

  • Oct 26, 2015 at 11:13 PM
    Add comment
    10|10000 characters needed characters exceeded

    • Thank you very much Dennis for your reply.  I have tried the "getSelectedButton" Method following your solution.  I might be missing the best way to adapt it to my code. in the Detail.controller.js file I declare the function as follows:

      onSelectRadio: function(oEvent) {
      var btn = this.getSelectedButton();
      var sKey  = btn.getBindingContext().getObject().key);
      alert(sKey);
      
      

      The Chrome Debugger informs: "Uncaught TypeError: this.getSelectedButton is not a function" as in this screenshot:

      Now the difference (I believe) is that in your jsBin the function is declared right away in the constructor. In my case, the function is in the controller and the RadioButtonGroup is created in the xml.view.

      How could I implement your code in my case? Thank you in advance,

      Gabriel

      pastedImage_1.png (17.8 kB)
  • Oct 27, 2015 at 06:47 AM

    Hi Gabriel,

    Will this help?

    JS Bin - Collaborative JavaScript Debugging

    Thanks,

    Karthik A

    Add comment
    10|10000 characters needed characters exceeded

    • Many Thanks Karthik for your answer. Perhaps I am not writing the collection name in the right way. In the screenshot of the debugger, I have highlighted in blue the path for each radiobutton.

      I have tried writting the collection name:

      - In this way -> "/ZUI5_TEST_TVALUES_SET/" ->

      or rather this one? "/ZUI5_TEST_TVALUES_SET(ATNAM='FIORI_BEZUGSSTOFF',ATWRT='KL')"

      I am obtaining from the debbuger the message: "Uncaught TypeError: Cannot read property 'getProperty' of null" in both cases.

      I appreciate your support,

      Kind Regards,

      Gabriel

      pastedImage_2.png (98.8 kB)