Display a message box in the external window just before the close event

I am trying to implement a message box that will appear when the user clicks the (X) button of an Ext window. However, I am facing an issue where the window closes before the message box is shown. Below is the code snippet I have written:

var assignReportFlag = 0;
var assignReportLoader = function(title,url){   
var panel = new Ext.FormPanel({
    id: 'arptLoader',
    height: 485,
    border: false,
    layout: 'fit',      
    autoScroll: true,
    method:'GET',
    waitMsg: 'Retrieving form data',
    waitTitle: 'Loading...',
    autoLoad: {url: url,scripts: true}
});

var cqok = new Ext.Button({
    text:'OK',
    id:'1',
    handler: function(){            
        if(assignReportFlag == 1){
            assignReportFlag = 0;
            Ext.MessageBox.alert('Status', 'Changes has been saved successfully',showResult);
        }else{
            assignReportWindow.close();         
        }           
    }
});

var assignReportWindow = new Ext.Window({       
    layout:'fit',
    title: title,       
    height:Ext.getBody().getViewSize().height - 60,
    width:Ext.getBody().getViewSize().width-20,
    closable: true,
    modal:true,
    resizable: false,
    autoScroll:true,
    plain: true,
    border: false,
    items: [panel],
    buttons: [cqok],
    listeners:{
        beforeclose:function(){
            if(assignReportFlag == 1){
                assignReportFlag = 0;
                Ext.MessageBox.alert('Status', 'Changes has been saved successfully',showResult);
            }else{
                assignReportWindow.destroy();           
            }
        }
    }
});

function showResult(btn){       
    assignReportWindow.destroy();   
};

assignReportWindow.show();
};

Thank you

Answer №1

When utilizing the beforeclose event listener, ensure to return false in order to prevent the close event from triggering.

Answer №2

This solution is working perfectly. Take a look below:

http://jsfiddle.net/DrjTS/266/

var customButton = new Ext.Button({
text:'OK',
id:'1',
handler: function(){            
        Ext.MessageBox.alert('Status', 'Changes have been saved successfully', showResult);
    }
 });

Ext.create('Ext.panel.Panel', {
title: 'Hello',
width: 200,
renderTo: Ext.getBody(),
items:[
        {
xtype:'button',
text:'SUBMIT',
            handler:function(thisobj)
            {
                Ext.create('Ext.window.Window', {
                id:'W',
                height: 200,
                width: 400,
                layout: 'fit',
                buttons: [customButton],
                listeners:{
                beforeclose:function(){
                            Ext.MessageBox.alert('Status', 'Changes have been saved');
                        }
                }    
                }).show();
            }
        }
       ]

    });

function showResult(btn){       
    Ext.getCmp('W').destroy();   
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for resolving the issue: "Encountered error loading module script..." in Angular 8 and Electron 5

I have been working on developing an Electron 5 app using Angular 8. Despite following numerous online tutorials, I keep encountering the same error. Initially, I set up a new project and ran ng serve --open, which successfully displayed the default angul ...

The controller failed to return a value when utilizing the factory

I am attempting to pass a value from my view to the controller using a function within the ng-click directive. I want to then use this value to send it to my factory, which will retrieve data from a REST API link. However, the value I am sending is not ret ...

Refresh MySQL database using AJAX

In my form, there are both a submit button and a close button. When a user enters information and clicks the submit button, an answer is posted and saved in the database. If the user chooses to click the close button instead, the entry in the database will ...

Keeping the header fixed on a sticky div (tocbot)

While working on my website, I decided to implement a Table of Contents section using tocbot. However, I encountered an issue where the Title I added above the table doesn't stay fixed when scrolling. https://i.stack.imgur.com/vCm1K.gif Here's ...

Border becomes dashed when dragging and dropping

I am working on enabling drag and drop functionality for users. When an item is lifted from its original position, a gray dashed box should appear in its place. As the item is moved closer to another spot, the containers adjust to create a target area (gra ...

How to achieve a seamless iframe effect using CSS

With the introduction of new HTML5 iframe attributes, there are now more options available. One such attribute is the seamless attribute, which has the ability to: Create an iframe that appears to be seamlessly integrated into the containing document. ...

Unable to get the deletion functionality to work for Dropzone.js and PHP script

I am currently using dropzone to handle file uploads. My goal is to delete the files on the server when the user clicks on the removeLink. I have implemented an Ajax function that calls a .php site for this purpose. However, I am facing an issue where I am ...

Switching between languages dynamically with Angular JS using $translateProvider and JSON files

I currently have a collection consisting of 6 different JSON files. en.json es.json fr.json it.json ja.json zh.json An illustration of the data present in each file is as follows (in this instance, considering en.json): { "SomeText": "Test in Englis ...

Encounter the "Error: Source 'cloudsTileLayer-RasterSource' not found" message while trying to integrate a weather tile layer into Azure Maps

I have been working on a React application that utilizes the React-Azure-Maps npm package. My current challenge involves creating a weather layer, which I believe shares similarities with the sample code provided for layers. The code snippet responsible f ...

Keep the music playing by turning the page and using Amplitude.js to continue the song

I have implemented Amplitude.js to play dynamic songs using a server-side php script. My objective is to determine if a song is currently playing, and if so, before navigating away from the page, save the song's index and current position (in percenta ...

Implement a dialog on top of a current web page, achieve php-ajax query result, and enhance with

My website features 'dynamic' content, where 'static' nav-buttons replace specific div contents upon clicking. While I am able to retrieve my php/ajax results in a dialog box, I am struggling with placing this dialog above my current p ...

Experimenting with NGXS selectors: A comprehensive guide

Hey there, I am currently utilizing the NGXS state management library in my application. I have a selector set up like this and everything seems to be functioning correctly. However, while testing the app, I encountered the following error message: "PrintI ...

What impact does nesting components have on performance and rendering capabilities?

Although this question may appear simple on the surface, it delves into a deeper understanding of the fundamentals of react. This scenario arose during a project discussion with some coworkers: Let's consider a straightforward situation (as illustrat ...

Adding and adjusting the size of different DIV elements within a shared area

Looking to create a dynamic bar with the ability to add multiple child DIVs (similar to this: https://i.stack.imgur.com/tdWsq.jpg). Utilizing jQuery, jQuery UI, Bootstrap, and various plugins. The structure for the div (or span) system could be structured ...

Can you point me in the direction of the Monaco editor autocomplete feature?

While developing PromQL language support for monaco-editor, I discovered that the languages definitions can be found in this repository: https://github.com/microsoft/monaco-languages However, I am struggling to locate where the autocompletion definitions ...

Best practices for displaying code blocks within an AngularJS application

Currently, I am in the process of building a website focusing on AngularJS within AngularJS ;-) To accomplish this, I have included ng-app within the body element. As a result, all my code snippets (enclosed in <pre><code> ... </code>&l ...

Screening data entries

.js "rpsCommonWord": [ { "addressWeightPct": "60", "charSubstituteWeightPct": "15", "nameWeightPct": "40", "oIdNumber": "21", "shortWordMinLthWeightPct": "100", "substituteWeightPct": "5", ...

When using Next.js revalidate, an error may occur stating: "There are keys that require relocation: revalidate

I have been attempting to utilize the revalidate function in my code by following the example provided by Vercel. However, I keep encountering an error. Here is the snippet of code that I am currently using: export async function getServerSideProps() { c ...

Tips on extracting information from an AJAX call using JQuery

My current project involves utilizing a webapi in asp.net that outputs JSON data. I am looking to integrate this webapi with JQuery within a php-created website. The following is the JQuery code I am using to retrieve information from the webapi: $.ajax( ...

Tips for streamlining the use of hidden and visible div elements with concise code

I have been attempting to use the same code for multiple modules on this page, but none of the methods I've tried seem to be effective. I want to avoid endlessly duplicating existing code. document.addEventListener('DOMContentLoaded', fun ...