How to confirm Ext window close

This is an archived post from the ExtJS era — the code may be obsolete, but the principles often still apply.

It may sometimes be needed to ask the user if he really wants to close an Ext window. Naturally, we would use Message Box for this purpose, and we would listen to beforeclose returning false if the user does not want to close, answers "No." And now comes the problem: Message Box is, unlike browser alert dialog, asynchronous. The execution of code does not stop when it is displayed but it immediately continues. We do not have time to evaluate the user response before returning false from the beforeclose event to cancel the close. Fortunately, solution is easy:

3 comments

  1. Tomas RSeptember 23, 2014archive
    Why not just call win.destroy() when the user confirms closing the window?
    1. Michal CharvatSeptember 25, 2014archive
      When you call destroy, the object with window, all descendant components will be destroyed too and window is removed from the DOM. However you have option select what do you want to do with window - I use mostly hide action instead of destroy. Check ExtJS doc: http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.panel.Panel-cfg-closeAction In Saki's example the window will be destroyed because defautl close action is 'destroy'
    2. SakiOctober 1, 2014archive
      Yes, exactly! Thanks Michal.

Comments are closed on archived posts.