Skip to content

ExtJS form cancel, Save Changes If Changes Have Been Made

Updated: at 02:12 PM

 

It seems like when a user cancels out of form after making changes, the obvious thing that should happen is:

image

 

image

The JavaScript Code is as follows:

onCancelbuttonsessionitemidClick: function(button, e, eOpts) {
        var form = button.up('form').getForm(),
            formWindow = button.up('window'),
            session = form.getRecord(),
            store = this.getSessionsStore();
    <span class="kwrd">if</span> (form.isDirty()) {
         Ext.Msg.show({
           title:<span class="str">'Save Changes?'</span>,
           msg: <span class="str">'Save Your Changes Before Exiting?'</span>,
           buttons: Ext.Msg.YESNOCANCEL,
             fn: <span class="kwrd">function</span>(text) {
                 <span class="kwrd">if</span> (text == <span class="str">'yes'</span>) {
                   form.updateRecord();
                   store.sync();
                   formWindow.destroy();
                 } <span class="kwrd">else</span> <span class="kwrd">if</span> (text === <span class="str">'no'</span>) {
                   formWindow.destroy();
                 } <span class="kwrd">else</span> <span class="kwrd">if</span> (text === <span class="str">'cancel'</span>) {
                    <span class="rem">// do nothing</span>
                 }
             }
        });
    } <span class="kwrd">else</span> {
        formWindow.destroy();
    }
},</pre>
Check out the ORM (Object Relational Mapper) PRISMA. The database access method I use in all my projects