Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked May 3rd 2010 by Florian Bergmann
  • backbutton
  • form
  • information
  • iphone
  • passing
  • textfield
  • window

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
    — answered May 3rd 2010 by Masood Nasir
  • 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") {
        form[e.fid] = e.value;
    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});
    — answered May 3rd 2010 by Florian Bergmann
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.