Search code examples
jqueryjquery-uidialogjquery-ui-dialogjquery-dialog

how to destroy jquery dialog when pressing escape?


how to destroy jquery dialog when pressing escape?

Is there a way to add a code like that: $.dialog('destroy');

inside of a close event? Here is the close event: It seens that the last 'else' has a hide method and this is the guy. But can´t destroy anything there:

close: function( event ) {
    var that = this,
        maxZ, thisZ;

    if ( !this._isOpen ) {
        return;
    }

    if ( false === this._trigger( "beforeClose", event ) ) {
        return;
    }

    this._isOpen = false;

    if ( this.overlay ) {
        this.overlay.destroy();
    }

    if ( this.options.hide ) {
        this._hide( this.uiDialog, this.options.hide, function() {
            that._trigger( "close", event );                
        });
    } else {
        this.uiDialog.hide();
        this._trigger( "close", event );
    }

Solution

  • Found a way of doing this editing directly the close event since I want this behavior in the whole application.

    From:

    else {
        this.uiDialog.hide();
        this._trigger( "close", event );
    }
    

    To:

    else {
        this.uiDialog.remove();
        this._trigger( "close", event );
    }
    

    thanks a lot!