Skip to content

Instantly share code, notes, and snippets.

@osmeest
Created August 5, 2010 10:14
Show Gist options
  • Save osmeest/509513 to your computer and use it in GitHub Desktop.
Save osmeest/509513 to your computer and use it in GitHub Desktop.
var common = { value: "123", title: "None" };
var tabGroup = Titanium.UI.createTabGroup();
for(var i = 0; i < 2; ++i) {
var win = Titanium.UI.createWindow({
title : "Test #" + i,
backgroundColor: '#fff',
url: "tab.js"
});
win.common = common;
var tab = Titanium.UI.createTab({
title: "Test " + i,
window: win
});
tabGroup.addTab(tab);
}
tabGroup.open();
var win = Titanium.UI.currentWindow,
common = win.common;
var field;
field = Titanium.UI.createTextField( {
value : "",
width : 90, height : 30, left: 10, top: 10,
borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(field);
win.addEventListener('focus', function(e) {
Ti.API.info('focus updating value: value=' + common.value + " title=" + common.title);
field.value = common.value;
common.title = win.title;
Ti.API.info('Now, value=' + common.value + " title=" + common.title);
});
win.addEventListener('blur', function(e) {
Ti.API.info('blur check: field=' + field.value + ' value=' + common.value + " title=" + common.title);
});
field.addEventListener('change', function(e) {
Ti.API.info('field changed value to ' + e.value);
common.value = e.value;
Ti.API.info('After update, value=' + common.value + " title=" + common.title);
});
@osmeest
Copy link
Author

osmeest commented Aug 5, 2010

Does not seem to work... Seems the common object is passed by value, not by reference as can be seen in the debug log:

[INFO] focus updating value: value=123 title=None
[INFO] Now, value=123 title=Test #0
[INFO] field changed value to 123a
[INFO] After update, value=123a title=Test #0
[INFO] blur check: field=123a value=123a title=Test #0
[INFO] focus updating value: value=123 title=None
[INFO] Now, value=123 title=Test #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment