Extjs Window Closing Event

I have a window with a cancel button and the default is [x]. When the user clicks the cancel button, he must check the specific flag and close the window and update db. I use me.close (this); to close the window for the cancel button. When the user clicks on [x], he must check one flag and update db, and then close the window. I added a listener to check this flag state. This listener works great. But after adding a listener by pressing the cancel button, the close event is called twice. Thus, db recovery occurs twice. Can anyone advise me how to handle the closing [x] event for a window

Ext.define('MyApp.view.updateForm', { extend: 'Ext.window.Window', height: 600, width: 800, layout: { type: 'absolute' }, title: 'Update Window', modal: true, initComponent: function() { Ext.applyIf(me, { items: [ { xtype: 'button', id:'btnCancel', handler : function(){ if(flag == true){ //add to db me.close(this); } } }] }); me.callParent(arguments); }, listeners:{ close:function(){ if(flag == true){ alert("close window"); //add to db } } } }); 
+4
source share
2 answers

I made this exact implementation with some minor differences, and I can confirm that it works exactly as expected.

Here is my code:

  Ext.create('Ext.window.Window', { ... buttons:[ { text:'Finish', handler:function () { this.up('window').close(); } } ], listeners:{ close:this.someFunction, scope:this } .... 

It works great. Which tells me that the problems are located elsewhere in your code.

+6
source

One fix would be to simply call close when the Cancel button is clicked. That is, do not check (flag == true) when you click Cancel . This will not cause a close call twice.

0
source

Source: https://habr.com/ru/post/1468937/


All Articles