PDA

View Full Version : Cloning Fields on event



heidtmare
8 Aug 2007, 6:07 AM
I was attempting to clone and display a fieldset and fields, but i was told i cant add containers after the initial page render.
http://extjs.com/forum/showthread.php?t=10685

So now, I'd just like to clone some fields when a user clicks a button.

lets keep it simple:

var simple = new Ext.form.Form({});

simple.fieldset({legend: 'Fieldset'});
textField = new Ext.form.TextField({fieldLabel: 'TextField', name: 'TextField'});
button = new Ext.Button(null,{ text: 'Clone TextField', handler: function(){ cloneTextField(textField); }} )
simple.add( textField );
simple.add( button );
simple.end();

simple.render('search_form');

function cloneTextField( textField )
{
simple.add( textField );
simple.render('search_form');//re-render?
}This doesn't work. I'm missing a vital concept but i can't put my finger on it.
Can anybody help?

para
8 Aug 2007, 10:52 AM
Re-rendering isn't the answer. I'm sure there is an easy way to do it.
If there isn't a built in way, then get the element that the form is using, erase the innerHTML, and then re-apply it to the element.
However, I can almost guarantee that someone else will reply within an hour with a 2-liner to solve your problem.

Edit: Ok, it may not be as easy as I thought...

heidtmare
8 Aug 2007, 11:20 AM
Edit: Ok, it may not be as easy as I thought...

:((