Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-7313

Android: Date Picker getValue throws an error, custom picker returns undefined

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: Release 1.8.0.1, Release 2.0.0, Release 2.0.1
    • Component/s: Android
    • Environment:

      Titanium SDK version: 1.8.0 / 1.8.0.1 / 1.9.0
      Platform OS: Android
      Platform OS Version: 2.3.3
      Device Details: simulator
      Host Operating System: OSX 10.7.2
      Titanium Studio Build 1.0.7.201112281340

      Description

      Actual Behavior

      The documentation about Pickers have a getValue method, as the getSelectedRow method, the customer try to reach the value at the Picker, and always throws an error: Object #<Picker> has no method 'getValue'

      Expected Behavior

      getValue method returns the value selected on a Picker column, or, clarify the documentation about how to use the method

      Code

      I'm using the code on the kitchen sink "picker_android_spinner_date.js" adding a button to call the method

      app.js

      /*global Ti,Titanium,alert */
      /*var w = Titanium.UI.createWindow({  
          title:'win1',
          backgroundColor:'#fff'
      });
      var status = Ti.UI.createLabel({
      	top: 5, left: 5, right: 5, height: 40, textAlign:'center'
      });
      w.add(status);
       
      function showStatus(s) {status.text = s;}
       
      var names = ['Joanie', 'Mickey', 'Jean-Pierre', 'Gustav', 'Raul', 'Mimi', 'Emily', 'Sandra', 'Carrie', 'Chachi'];
      var verbs = ['loves', 'likes', 'visits', 'loathes', 'waves to', 'babysits', 'accompanies', 'teaches', 'announces', 'supports', 'knows', 'high-fives'];
       
      var rows1 = [];
      for (var i = 0; i < names.length; i++) {
      	rows1.push(Ti.UI.createPickerRow({title: names[i]}));
      }
       
      var rows2 = [];
      for (i = 0; i < verbs.length; i++) {
      	rows2.push(Ti.UI.createPickerRow({title: verbs[i]}));
      }
       
      var rows3 = [];
      for (i = (names.length -1); i >=0; i--) {
      	rows3.push(Ti.UI.createPickerRow({title: names[i]}));
      }
       
      var column1 = Ti.UI.createPickerColumn( {
      	rows: rows1, font: {fontSize: "12"}
      });
      var column2 = Ti.UI.createPickerColumn( {
      	rows: rows2, font: {fontSize: "12"}
      });
      var column3 = Ti.UI.createPickerColumn( {
      	rows: rows3, font: {fontSize: "12"}
      });
       
      var picker = Ti.UI.createPicker({
      	useSpinner: true, visibleItems: 7,
      	type : Ti.UI.PICKER_TYPE_PLAIN,
      	top: 150, height: 200,
      	columns: [ column1, column2, column3 ]
      });
       
      picker.addEventListener('change', function(e) {
      	showStatus(e.selectedValue[0] + " " + e.selectedValue[1] + " " + e.selectedValue[2]);
      });
       
      w.add(picker);
       
       
      var btnCheckSelection = Ti.UI.createButton({
      	left: 165, height: 40, top: 100, width: 150,
      	title: 'Check sel.'
      });
      btnCheckSelection.addEventListener('click', function() {
      	showStatus(picker.getSelectedRow(0).title + ' ' + picker.getSelectedRow(1).title + ' ' + picker.getSelectedRow(2).title);
      	for (i in picker.getSelectedRow(0)){
      		Ti.API.info('i--- '+i);
      	}
      	Ti.API.info('the value------ '+picker.getValue());
      	var color = status.backgroundColor || w.backgroundColor || "black";
      	status.backgroundColor = 'red';
      	setTimeout(function(){status.backgroundColor=color;},1000);
      });
      w.add(btnCheckSelection);
      w.open();*/
       
       
       
       
      var win = Titanium.UI.createWindow({  
          title:'win1',
          backgroundColor:'#fff'
      });
       
      var minDate = new Date();
      minDate.setFullYear(2009);
      minDate.setMonth(0);
      minDate.setDate(1);
       
      var maxDate = new Date();
      maxDate.setFullYear(2009);
      maxDate.setMonth(11);
      maxDate.setDate(31);
       
      var value = new Date();
      value.setFullYear(2009);
      value.setMonth(0);
      value.setDate(1);
       
      var picker = Ti.UI.createPicker({
      	useSpinner: true,
      	type:Ti.UI.PICKER_TYPE_DATE,
      	minDate:minDate,
      	maxDate:maxDate,
      	value:value
      });
       
      // turn on the selection indicator (off by default)
      picker.selectionIndicator = true;
       
      win.add(picker);
       
      var label = Ti.UI.createLabel({
      	text:'Choose a date',
      	top:6,
      	width:'auto',
      	height:'auto',
      	textAlign:'center',
      	color:'white'
      });
      win.add(label);
       
      picker.addEventListener('change',function(e)
      {
      	label.text = e.value;
      });
       
      var locale = false;
      var localebutton = Ti.UI.createButton({
      	title:'Change locale',
      	bottom:20,
      	width:200,
      	height:40
      });
      localebutton.addEventListener('click', function() {
      	if (!locale) {
      		picker.setLocale('ru');
      		locale = true;
      	}
      	else {
      		locale = false;
      		picker.setLocale(Titanium.Platform.locale);
      	}
      });
      win.add(localebutton);
       
      var button = Ti.UI.createButton({
      	title:'Get Value',
      	top:20,
      	width:200,
      	height:40
      });
      button.addEventListener('click', function(e){
      	Ti.API.info('picker value-> '+picker.getValue());
      });
      win.add(button);
      win.open();
      

      Another approach

      I try to use the method with another picker, using part of the kitchen sink "picker_android_spinner_text.js", the method always returns null or undefined

      app.js

      var w = Titanium.UI.createWindow({  
          title:'win1',
          backgroundColor:'#fff'
      });
      var status = Ti.UI.createLabel({
      	top: 5, left: 5, right: 5, height: 40, textAlign:'center'
      });
      w.add(status);
       
      function showStatus(s) {status.text = s;}
       
      var names = ['Joanie', 'Mickey', 'Jean-Pierre', 'Gustav', 'Raul', 'Mimi', 'Emily', 'Sandra', 'Carrie', 'Chachi'];
      var verbs = ['loves', 'likes', 'visits', 'loathes', 'waves to', 'babysits', 'accompanies', 'teaches', 'announces', 'supports', 'knows', 'high-fives'];
       
      var rows1 = [];
      for (var i = 0; i < names.length; i++) {
      	rows1.push(Ti.UI.createPickerRow({title: names[i]}));
      }
       
      var rows2 = [];
      for (i = 0; i < verbs.length; i++) {
      	rows2.push(Ti.UI.createPickerRow({title: verbs[i]}));
      }
       
      var rows3 = [];
      for (i = (names.length -1); i >=0; i--) {
      	rows3.push(Ti.UI.createPickerRow({title: names[i]}));
      }
       
      var column1 = Ti.UI.createPickerColumn( {
      	rows: rows1, font: {fontSize: "12"}
      });
      var column2 = Ti.UI.createPickerColumn( {
      	rows: rows2, font: {fontSize: "12"}
      });
      var column3 = Ti.UI.createPickerColumn( {
      	rows: rows3, font: {fontSize: "12"}
      });
       
      var picker = Ti.UI.createPicker({
      	useSpinner: true, visibleItems: 7,
      	type : Ti.UI.PICKER_TYPE_PLAIN,
      	top: 150, height: 200,
      	columns: [ column1, column2, column3 ]
      });
       
      picker.addEventListener('change', function(e) {
      	showStatus(e.selectedValue[0] + " " + e.selectedValue[1] + " " + e.selectedValue[2]);
      });
       
      w.add(picker);
       
       
      var btnCheckSelection = Ti.UI.createButton({
      	left: 165, height: 40, top: 100, width: 150,
      	title: 'Check sel.'
      });
      btnCheckSelection.addEventListener('click', function() {
      	showStatus(picker.getSelectedRow(0).title + ' ' + picker.getSelectedRow(1).title + ' ' + picker.getSelectedRow(2).title);
      	for (i in picker.getSelectedRow(0)){
      		Ti.API.info('i--- '+i);
      	}
      	Ti.API.info('the value------ '+picker.getValue());
      	var color = status.backgroundColor || w.backgroundColor || "black";
      	status.backgroundColor = 'red';
      	setTimeout(function(){status.backgroundColor=color;},1000);
      });
      w.add(btnCheckSelection);
      w.open();
      

        Attachments

          Activity

            People

            • Assignee:
              joshroesslein Josh Roesslein
              Reporter:
              rtlechuga Radamantis Torres-Lechuga (Inactive)
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-11823
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration