PDA

View Full Version : beforedestroy on formpanel



ImShogun
18 Jan 2010, 7:54 AM
Hi, I have a tree on the left and for each node of that tree, a formpanel is rendering on the right.

I'm trying to check if that form has been changed and to warn for saving the changes if any when I'm clicking on another tree node (or anywhere else on the interface that would replace my rendered form).

For that, I tought I would use the beforedestroy event of this formpanel, trigger a confirmation window, and cancel the orignal click action if the user choose cancel.

Here is the code ( right now, I bypassed the user confirmation and am trying to cancel the destroy event anyway ) :



//DETAILS PANEL
function CreateDetailsPanel(MyFormStructure,node_id){
//console.log(node_id);
var pan3 = new Ext.Panel({
id:'DetailsPanel',
xtype : 'form',
labelWidth:200,
padding:'5 5 5 5',
frame:false,
autoScroll : true,
title : 'Details',
iconCls : 'search_page',
items: [{
xtype: 'tabpanel',
width:650,
height:550,
activeTab: 0,
items: [{
title: 'Main',
padding: '10 10 10 10',
labelWidth: 200,
layout: 'form',
autoScroll:true,
items: MyFormStructure
//,buttons: [{ text: 'Login'},{text:'Cancel'}]
}]
}],
tbar:[
{
text:'Highlight this node',
iconCls:'back',
qtip:'Highlight this node in the Budget Tree',
listeners:{
click:function(){
var MyNode = MyTree.getNodeById(node_id);
var MyPath= MyNode.getPath();
MyTree.selectPath(MyPath);
}
}
}
],
listeners: {
beforedestroy: function(panel){
console.log(panel);
Ext.Msg.show({
title:'Save your work?',
icon: Ext.MessageBox.QUESTION,
msg:'You did some changes on this form. Are you sure you want to leave without saving?',
minWidth:300,
buttons: Ext.Msg.YESNO
});

return false;
}
}
});
return pan3;
};
The thing is: I understand that even if my code is maybe attempting to cancel the destroy, somewhere else, due to my click, it is still trying to override it with something else. What I don't understand is where and how I'm supposed to cancel the click event itself?

Thank you very mutch for your enlightened tips :-)

21 Jan 2010, 5:23 AM
Look at the API. The click event will pass the event object, which is what you'll do to cancel the click event.

ImShogun
28 Jan 2010, 5:09 AM
Hello J. I must confess I did not understood your answer. But anyway I decided o handle the warning in a different way, precisely with adding click events to the two possible actions that would have destroyed the form.

And sorry for the delay reading you. When i asked, the formum was down for a time.

Regards.