PDA

View Full Version : How to implement "Do not leave the form under editing"



cblin
4 Oct 2010, 1:01 AM
At the moment, I am trying to implement a feature request that says "if a form is edited, the user must not be able to leave the form without a warning message if he did not use one of the 2 buttons (save or cancel)"

The warning message is something like "Are you sure to leave the current form without saving modifications ?" -> yes/no

If the user says yes (he is sure to lose his modifications), we must continue the screen workflow otherwise we must stay on the current screen.

The conclusion I made from my current investigations is that ExtJs provide no way to help me because there is no beforelostfocus event on the Panel

So, for a tabpanel, I have to be aware of beforetabchange so that if the user says yes I must manually activate the panel that was going to be activated

So, for a gridpanel, I have to be aware of selModel.beforerowselect or beforecellselect

So basically my current solution is to implement a plugin with a singleton that knows which component is edited and so I can make my best to return false on the given events.

Is there a better way ?

laurentParis
4 Oct 2010, 1:52 AM
Every links on menus, buttons... pass by same method with argument : url

* on this method, test if on your page you have or not a form
* if yes, test form is dirty => yes => msgBox (redirect or cancel redirect)...

cblin
4 Oct 2010, 6:20 AM
Hi,

I do not follow you : I have only one page in my application (i.e with multiple tabs, each tab has a form so I have something like 20 form on my current page). How do I know which form I am currently leaving ?

Condor
4 Oct 2010, 6:27 AM
You don't. You can only use the beforetabchange events of the various tabpanels to check if the current form has pending changes.

cblin
4 Oct 2010, 6:41 AM
That was what I was thinking...

I also tried the global event approach (i.e Ext.util.Observable.observeClass(Ext.TabPanel, {beforetabchange: function(){return false}}) but this does not work because of a strange behavior in createInterceptor (see http://www.sencha.com/forum/showthread.php?111475)