Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7355] Android: children[] 'undefined' for table rows within event handler

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-02-14T23:28:59.000+0000
Affected Version/sRelease 1.8.0.1, Release 1.8.1
Fix Version/sSprint 2012-03, Release 2.0.0, Release 1.8.2
ComponentsAndroid
Labelsregression
ReporterTim Poulsen
AssigneeHieu Pham
Created2012-01-24T11:33:56.000+0000
Updated2012-02-14T23:28:59.000+0000

Description

Expected Results

I should be able to read from e.row.children[] within a table's event listener. This works fine on iOS (simulator and my iPad running iOS5) and works with TiAPI 1.7.5/1.7.6 on Android.

Actual results

Code below throws Uncaught TypeError: Cannot set property 'text' of undefined
var table = Ti.UI.createTableView();
function makeRow(num) {
	var row = Ti.UI.createTableViewRow({
		height:60,
		rowID: num
	});
	row.add(Ti.UI.createLabel({
		font:{
			fontWeight:'bold',
			fontSize:16
		},
		left:5,
		top: 0,
		text:'Row '+num
	}));
	row.add(Ti.UI.createLabel({
		font:{
			fontWeight:'normal',
			fontSize:13
		},
		left:5,
		top: 35,
		text:'Subtitle for Row '+num		
	}));
	return row;
}
for(var i=0;i<6;i++) {
	table.appendRow(makeRow(i));
}
table.addEventListener('click', function(e){
	e.row.children[1].text = 'You clicked row '+ e.index;	
});

win1.add(table);

Comments

  1. Hieu Pham 2012-02-05

    The sample test code doesn't work. Also e.row.children is READ-ONLY (refer to docs). Test Code:
       var win1 = Ti.UI.createWindow({fullscreen:false});
       var table = Ti.UI.createTableView();
       function makeRow(num) {
       	var row = Ti.UI.createTableViewRow({
       		height:60,
       		rowID: num
       	});
       	row.add(Ti.UI.createLabel({
       		font:{
       			fontWeight:'bold',
       			fontSize:16
       		},
       		left:5,
       		top: 0,
       		text:'Row '+num
       	}));
       	row.add(Ti.UI.createLabel({
       		font:{
       			fontWeight:'normal',
       			fontSize:13
       		},
       		left:5,
       		top: 35,
       		text:'Subtitle for Row '+num		
       	}));
       	return row;
       }
       for(var i=0;i<6;i++) {
       	table.appendRow(makeRow(i));
       }
       table.addEventListener('click', function(e){
           Ti.API.info ("row: " + e.row);
           Ti.API.info (e.row.children[1].text);
       	//e.row.children[1].text = 'You clicked row '+ e.index;	
       });
       
       win1.add(table);
       win1.open();
       
    Test Instructions: 1. Run app 2. Click on a row and you should see "Subtitle for row ..."
  2. Nikolai Derzhak 2012-02-06

    This issue latest notification was not sent due to JIRA mail setting. Fixed now. Please check the issue for latests changes.
  3. Tim Poulsen 2012-02-10

    e.row.children (the array) has always been read only. But the properties of the children have always been read/write. Are you closing this without action? Are properties of children now unwriteable? That is a change that will cause problems.
  4. Ivan Skugor 2012-02-10

    I totally agree with Tim. As a workaround, custom property can be added to the row:
       var label = Ti.UI.createLabel();
       row.add(label);
       row.Label = label;
       
       //in event listener
       e.row.Label.text = 'Test';
       
  5. Neeraj Gupta 2012-02-10

    Opening this issue based on Tim's comments. We need to address these concerns.
  6. Hieu Pham 2012-02-10

    You can change the children properties. For example, e.row.children[0].backgroundColor = ...; The scope of this bug is to properly expose children[], not to change existing behaviors.
  7. Tim Poulsen 2012-02-10

    The scope of this ticket was that with 1.8.1 you cannot change the properties of children. The code I submitted certainly does work and demonstrate that. However, I can confirm that the code as I supplied does work on the 1.9 branch. Thus I'm fine with closing this ticket now.

JSON Source