Add Listener on win.backButton
Is it possible to add an eventListener on win.backButton?
I'm trying to save some information from a textfield when user clicks the back button.
currently i'm passing the information to the "mother window" when the textfield blurs. on the simulator a blur event is fired even when clicking the back button but not on the iphone device.
any idea?
thank you
2 Answers
-
Accepted Answer
You can replace the left nav button with a custom button and then add Event Listener to it. This works in simulator:
var win = Titanium.UI.currentWindow; var b = Titanium.UI.createButton({title:'Back'}); win.leftNavButton = b; b.addEventListener('click', function() { alert('I was clicked'); // to confirm its being called // do the stuff here win.close(); });
-
Thank you, great. I've made now a much more complex solution but it works too and might be handy in some other case:
on the main window:
Titanium.App.addEventListener('saveForm', function(e){ if (e.fid == "domagic" && e.value == "true") { doMagic(); }else{ form[e.fid] = e.value; nomagic(); } } childWin.addEventListener("close", function(e) { if (form.foobar != "") { Titanium.App.fireEvent("saveForm",{form: "domagic", value: "true"}); } else { Titanium.App.fireEvent("saveForm",{form: "domagic", value: "false"}); } }
and on the child window
someField.addEventListener('change', function(e){ Titanium.App.fireEvent("saveForm",{form: e.source.fid, value: e.source.value}); });