View Full Version : Beforeclose Listener

16 Aug 2012, 4:10 AM
Hi, I am listening to a panel's beforeclose event. It is a form I check updates in. I send an Ext.MessageBox.confirm when it was updated. Then I have three possibilities :

If they click on Yes, I save the changes, and close the panel.
If they click on No, I simply close the panel.
If they click on Cancel, I have to block panel's closure and let the user continue in this panel.
This is for the third point I have difficulties : I don't know how to stop the closure. It is said on docs that I must return false from a listener, but I can't manage to do it. So if you know how to do that, please help !

16 Aug 2012, 4:28 AM
Keep in mind that Ext.Msg.confirm(<...>) is asynchronous and doesn't halt execution, so you're most likely falling straight on through the beforeclose event handling code, which returns a true by default.

17 Aug 2012, 4:47 AM
Thanks for your answer. Do you know then how to configure beforeclose event so it can return 'false' to stop the close event ?

17 Aug 2012, 10:27 AM
It sounds like you may need to rethink your event handling and where/when you present the MessageBox to the user.

Can you provide a pared-down code sample which more clearly illustrates what you're trying to accomplish?

19 Aug 2012, 10:48 PM
Here it is :

var storeCompEC = Ext.create('Ext.data.Store', { fields: [
{name: 'idCivilite', type: 'integer'},
{name: 'patronyme', type: 'string'},
{name: 'nomIndividu', type: 'string'},
{name: 'prenom', type: 'string'},
{name: 'dateNaissance', type: 'date'},
{name: 'sexe', type: 'string'},
{name: 'idPCS', type: 'integer'},
{name: 'idSituationFamiliale', type: 'integer'},
{name: 'idPays', type: 'integer'},
{name: 'NIR', type: 'string'},
{name: 'dateDeces', type: 'date'},
{name: 'idJustificatifDeces', type: 'integer'}

Ext.define('Infologis.controller.Beneficiaire', {
extend: 'Ext.app.Controller',

//Les vues contrôlées
views: [

init: function() {
ctrler=this; this.control({
beforeclose: this.saveEC

saveEC: function(pan)
var modif = false;
var comp = storeCompEC.data.items[0].data;
var data = pan.child('form[name="centre"]').getValues();
var nomsCps = storeCompEC.model.getFields();
for (var i in nomsCps) {
var nam = nomsCps[i].name;
if(data[nam] != comp[nam]) {
modif = true;
if(modif) {
title: 'Confirmer',
msg: 'L\'enregistrement a été modifié.\nVoulez-vous enregistrer les modifications ?',
buttons: Ext.MessageBox.YESNOCANCEL,
fn: function(btn) {
if(btn == 'yes') {
url: 'individu/update-etat-civil',
params: data,
success: function() {
Ext.MessageBox.alert('Succes !', 'Les changements ont ete enregistres.');
// let panel's closure go
failure: function() {
Ext.MessageBox.alert('Erreur !', 'Une erreur est survenue durant l\'operation de mise à jour.');
// stop panel's closure
} else if(btn == 'cancel') {
// stop panel's closure

I hope it'll help you helping me :D