Search code examples
javascripthtmlradio-buttonwebix

How to get the text value of a Webix radio button?


How to get value of the Webix ui.radio option? The getValue() method returns only ID os the selected one, as well as the first parameter in onChange. Is this possible at all? Thanks.

The sample:

{
  view:"radio",
  label:"uiRadio",
  options:[
    { id:1, value:"Test 1"},
    { id:2, value:"Test 2"},
    { id:3, value:"Test 3"}
  ], 
  on:{ onChange:function(newV){ 
    webix.message(this.getValue()+"  "+newV)
  }}
}

http://webix.com/snippet/3e1adc6f


Solution

  • It's not pretty but this is what I came up with:

    webix.ui({
      view:"radio",
      label:"uiRadio",
      options:[
        { id:1, value:"Test 1"},
        { id:2, value:"Test 2"},
        { id:3, value:"Test 3"}
      ], 
      on:{ onChange:function(newV){ 
        var textValue = this.data.options
                      .filter(function(el) {return el.id == newV})
                      [0].value
    
        webix.message(newV + ": " + textValue)
      }}
    });