PDA

View Full Version : New function in BaseForm



steph04
29 Feb 2008, 5:30 AM
Hi,

I have a list of objects in a grid and when I select an object I load in a form the data of the object. To verify if it has changed (and save power) when I selected another object I implement a new feature.

I have implemented a new feature in a new class that extends "BaseForm" which call "isChanged", and i have override the method "createForm" in a new class that extends "FormPanel":

Ext.form.myFormPanel = Ext.extend(Ext.form.FormPanel, {
createForm: function(){
delete this.initialConfig.listeners;
return new Ext.form.myBasicForm(null, this.initialConfig);
}
});

Ext.form.myBasicForm = Ext.extend(Ext.form.BasicForm, {
isChanged: function(){
var changed = false;
values = this.getValues();

this.items.each(function(f){
if(String(values[f.name]) != String(f.value)) {
changed = true;
return false;
}
});
return changed;
}
});

It might well be that this feature to add to your library

You are doing great work

thanks

St

Animal
29 Feb 2008, 6:37 AM
Similar to http://extjs.com/deploy/dev/docs/?class=Ext.form.BasicForm&member=isDirty ?

CPliskin
29 Feb 2008, 6:40 AM
Have you seen isDirty method of BasicForm (http://extjs.com/deploy/dev/docs/?class=Ext.form.BasicForm&member=isDirty)?

steph04
29 Feb 2008, 7:05 AM
"isDirty" method compares the object between 2 loads of the same object. In my case, I load a different object (the one selected in the grid), therefore the method "isDirty" fails to answer my problem

For example:

When I click on a object in my grid I load this object in my form, but I click on an other object I load a different object (And the method "isDirty" returns therefore always true). With the method "isChanged" I compare the status of my first object in the form with its status before I load the second object

CPliskin
29 Feb 2008, 7:31 AM
When I click on a object in my grid I load this object in my form, but I click on an other object I load a different object (And the method "isDirty" returns therefore always true). With the method "isChanged" I compare the status of my first object in the form with its status before I load the second object

I'm using beforerowselect event in selection model (http://extjs.com/deploy/dev/docs/?class=Ext.grid.RowSelectionModel&member=beforerowselect) + other events such as request of the other page, window unload, etc. to call form's isDirty before the requested action is done.

steph04
29 Feb 2008, 7:50 AM
I try to use your solution but I have the same problem

CPliskin
29 Feb 2008, 10:10 AM
I try to use your solution but I have the same problem

Have You tried to set trackResetOnLoad: true on your form?