Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9054] Android: Loosing the value of the source in an event

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-07-11T02:02:34.000+0000
Affected Version/sRelease 2.0.1
Fix Version/sRelease 2.0.2, Release 2.1.0, Sprint 2012-10 API
ComponentsAndroid
LabelsSupportTeam, api, module_view, qe-testadded, regression
ReporterMauro Parra-Miranda
AssigneeJosh Roesslein
Created2012-05-08T10:38:02.000+0000
Updated2013-11-07T05:51:25.000+0000

Description

Problem Description

When processing custom events, the source of the event is not passing complete. This used to work in SDK 1.7.6.

Actual Results

The source of the event is not complete, so it's failing.

Expected results

The events working as before

Test Case

1. Create a new mobile Project 2. PAste this:
var fundListSize,fundCheckboxArray=[],fundsToPlotCount,grey=false,lightBlue=false,clickEvent=false,fundsSitemanagerMsg=null;
var win = createHistoricalFundGraphFundsWindow();
win.orientationModes = [Titanium.UI.LANDSCAPE_LEFT, Titanium.UI.LANDSCAPE_RIGHT];
win.open()
 
/*
 * Function to display the available funds that can be selected to display on the graph
 */
function createHistoricalFundGraphFundsWindow() {
	/* Declaring the variables*/
	var iOSTopTitle, planText, navTitleText, menuTitle, winLeftNavButton, winRightNavButton, winBackButtonTitle, winBackButtonTitleImage, winTabBarHidden, subHeader, tableViewDS, genericTableView, win;
	fundsSitemanagerMsg = ''//_response.historicalFundGraphFundMessage;
	fundsToPlotCount = 3;

    /* reset fundlistsize*/
	fundListSize = 0;
 
	tableViewDS = createHistoricalFundGraphFundsTableViewDS();
	genericTableView = Titanium.UI.createTableView({
		separatorColor:'#e7e7e7',
		data : tableViewDS,
		backgroundColor :'#e7e7e7'
	});
    
	genericTableView.top = 0;
	genericTableView.backgroundColor = '#e7e7e7';
	tableViewDS = null;
                 
	var menuWindow = Titanium.UI.createWindow({
		barColor : '#929292',
		backgroundColor : '#E7E7E7'
	});
    
	menuWindow.add(genericTableView);
	return menuWindow;
};
 
/*
 * Function to create the data source to be added to the tableview that displays the funds
 */
function createHistoricalFundGraphFundsTableViewDS() {
	var responseLength=2;
	var datasource=[];
	var datasourceChecked=[];
	var fundRow,boxChecked;
	boxChecked=false;
	fundCheckboxArray.push(createHFGCheckBox('','xyz',boxChecked));
	fundCheckboxArray.push(createHFGCheckBox('','abc',boxChecked));
	fundRow=createHFGRowLndScpe({
		fFundName: 'xyz',
		sSwitch: fundCheckboxArray[0]
	});
	var fundRow1=createHFGRowLndScpe({
		fFundName: 'abc',
		sSwitch: fundCheckboxArray[1]
	});

	datasource.push(fundRow);
	datasource.push(fundRow1);
	fundListSize = 2;
	return datasource;
};
/*
 * function to create checkbox ( a button masked as checkbox, not a switch ) for each row
 */
function createHFGCheckBox(_fundNum,_fundName,_checked) {
 
	var checkbox = Ti.UI.createButton({
		title:'',
		right:'5%',
		width:28,
		height:28,
		font: {
			fontSize: 14,
			fontWeight: 'bold'
		},
		value:_checked,
		fundNum:_fundNum,
		fundName:_fundName,
		checkColor:'none'
	});

	/* attach on/off actions */
	checkbox.on = function() {
		this.value = true;
		this.title='ON';
	};
	checkbox.off = function() {
		this.value = false;
		this.title='OFF';
	};
 
	/* fire action to check or uncheck based on _checked bool param */
	if (_checked) {
		checkbox.on();
	} else {
		checkbox.off();
	}
 
	checkbox.addEventListener('updateCheckBox', function(e) {
		alert(e)
		/* can always turn checkboxes off */
		if(e.source.value == true)
		{
			checkbox.off();
		}
		else
		{
			checkbox.on();
		}
	});
	return checkbox;
};
     
/*
 * Function to create  row for fund label
 */
function createHFGRowLndScpe(_fundBalData) {
	if( typeof _fundBalData !== 'undefined' && _fundBalData !== null) {
		var _fundName = _fundBalData.fFundName;
		var row = Titanium.UI.createTableViewRow({
			backgroundColor : '#FFFFFF',
			selectedBackgroundColor : '#FFFFFF',
			selectionStyle : 'NONE'
		});
		var checkBoxView = Ti.UI.createView({
			right : 0,
			height : 30,
			width : '30%',
		})
		row.addEventListener('click', function(e) {
			var id = e.index;
			Ti.API.info('Row got click Source: '+e.source+' Row Index:'+e.index);
			if( typeof id !== 'undefined' && id !== null) {
				fundCheckboxArray[id].fireEvent('updateCheckBox');
    		}
		});
		var fundNameLabel = Titanium.UI.createLabel({
			left : '5%',
			width : '65%',
			top : 15,
			bottom : 15,
			height : 'auto',
			color : '#363636',
			text : _fundName,
			font : {
				fontSize : 15,
				fontFamily : 'Helvetica Neue',
				fontWeight : 'bold'
			},
		});
		row.add(fundNameLabel);
		_fundName = null;
		checkBoxView.add(_fundBalData.sSwitch);
		row.add(checkBoxView);
		return row;
	}
};
3. Test in 1.7.6, working fine. 4. Now test in 2.1CI, it will fail.

Extra info

The interesting part is
checkbox.addEventListener('updateCheckBox', function(e) {
		alert(e)
		/* can always turn checkboxes off */
		if(e.source.value == true)
		{
			checkbox.off();
		}
		else
		{
			checkbox.on();
		}
	});

Attachments

FileDateSize
alert.png2012-05-08T10:39:36.000+000040692
error.png2012-05-08T10:39:36.000+000061925

Comments

  1. Mauro Parra-Miranda 2012-05-08

    The Alert attachment is the one coming from 1.7.6, working fine. The error one is from 2.1CI. Best, Mauro
  2. Josh Roesslein 2012-05-09

    Here's a simplified test case:
       var win = Ti.UI.createWindow();
        
       var view = Ti.UI.createView({
           backgroundColor: "blue"
       });
       win.add(view);
        
       view.addEventListener("myEvent", function(e) {
           e.source.backgroundColor = "red";
           alert("Message: " + e.message);
       });
        
       view.addEventListener("click", function(e) {
       	var data = {message: "Hello!"};
       	e.source.fireEvent("myEvent", data);
       	if (data.hasOwnProperty("source")) {
       		alert("Error: data modified!");
       	}
       });
        
       win.open();
       
    1. Run application. 2. Color should be blue initially. 3. Click the view. 4. Color should now be red. An alert should appear saying: "Message: Hello!". 5. No "Error" alerts should appear.
  3. Josh Roesslein 2012-05-09

    [PR #2159](https://github.com/appcelerator/titanium_mobile/pull/2159) submitted to address issue.
  4. Mauro Parra-Miranda 2012-05-09

    Hello Josh, do you think that will be in for today's or tomorrow's CI? Best, Mauro
  5. Josh Roesslein 2012-05-09

    Mauro, I would expect tomorrow, but depends on how quickly it can get reviewed. A possible workaround might be to just use the variable "checkbox" directly rather than using "e.source". Example:
       checkbox.addEventListener("updateCheckBox", function() {
         checkbox.value; // <--- you can check value here
       });
       
  6. Josh Roesslein 2012-05-16

    Re-opening to deal with regression on Rhino runtime.
  7. Natalie Huynh 2012-05-17

    Tested with 2.0.2.v20120517141652 on LG Revolution 2.3.6 and Emulator 2.3.3
  8. Neha Chhabra 2012-07-11

    Reopening to update labels.
  9. Shameer Jan 2013-11-07

    Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/4887

JSON Source