View Full Version : deep copy/clone formpanel

6 Jul 2010, 6:26 AM

How do I make a deep copy of a FormPanel?
Something like :

var newform = deepcopy(existingform);



6 Jul 2010, 6:56 AM
And with a deep copy you mean a copy with all nested components?

That's not 100% possible in Ext. You are better of creating a factory method that returns instances of the same form.

6 Jul 2010, 7:27 AM
ok, is that by just giving the existing form as an argument to the
constructor of the FormPanel class? And if I have two instances
will a change of a value in oneinstance also change it in the other


6 Jul 2010, 8:17 AM
Condor means that instead of instanciating each formpanel on its own, like

var fp1 = new Ext.form.FormPanel({
title: 'panel1',
items: [
{ fieldLabel: 'value1', name: 'value1' }
var fp2 = new Ext.form.FormPanel({
title: 'panel2',
items: [
{ fieldLabel: 'value1', name: 'value1' }
you should wrap the instanciating in its own function and only pass in the differing values, e.g.

createfp = function(conf) {
return new Ext.form.FormPanel(
items: [
{ fieldLabel: 'value1', name: 'value1' }
}, conf);
var fp1 = createfp({title: 'panel1'});
var fp2 = createfp({title: 'panel2'});

If you try to deep copy values from an existing formpanel instance, you'll likely get in over your head, as it is almost impossible to check exactly how deep you need to copy (just think about layout managers or plugins that store ids of child elements at creation time).