Search code examples
javascripttitaniumtitanium-mobiletitanium-alloy

How to get the picker value in controller using Titanium Alloy?


How can we get the selected picker value in controller and do the validation of the selected value.

View:

  <Picker id="countryPicker" class="picker">
            <PickerRow title="Select a Country"/>
            <PickerRow title="India"/>
            <PickerRow title="China"/>
  </Picker>

Controller:

var countryname = $countryPicker.value();
alert("country: "+ countryname);
$.planWin.open();

Did validation done in controller or some other module?


Solution

  • Put an event listener for change event fired when selecting a picker item ...

    $.countryPicker.addEventListener('change',function(e){
     //do your stuff here 
    });
    

    on change event you can access selected item using event object (e) :

    e.column, e.rowIndex, ...
    

    refer to the official docs fro more information and use cases ...