Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs window close event

Tags:

extjs4

I have a window with cancel button and the default close[x]. When the user clicks cancel button, it should check for a specific flag and the close the window and updates db. I am using me.close(this); for closing the window for cancel button. When the user clicks on [x], it should check for the same flag and updates db and then close the window. For checking that flag condition, I added a listener This listener works fine. But after adding the listener, clicking the cancel button, the close event is called twice. So the db updation happens twice. Could someone advice me how to handle the [x] close event for the 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
            }
        }
    }

});
like image 672
user1049057 Avatar asked Mar 13 '13 10:03

user1049057


People also ask

How do I close a window in Extjs?

It's just close() .

What does window close() do?

The Window. close() method closes the current window, or the window on which it was called. This method can only be called on windows that were opened by a script using the Window.

How to close a particular window in JavaScript?

The close() method closes a window.


1 Answers

I have done this exact implementation with some minor differences and can attest that this 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
        }
      ....

This works perfectly. Which tells me that the issues is elsewhere in your code.

like image 156
dbrin Avatar answered Oct 01 '22 13:10

dbrin