PDA

View Full Version : [solved] Adding textfield to form dynamically



kkamis
20 Dec 2010, 8:35 AM
Hi,

Im new in extjs and I have a problem. Here is my code



Ext.onReady(function() {
var form = new Ext.FormPanel({
xtype: 'form',
title: 'My Form',
id: 'myform',
padding: 20,
autoWidth: true,
autoHeight: true,
items: [
{
xtype: 'textfield',
fieldLabel: 'Tytu?',
anchor: '100%',
emptyText: 'Empty text',
name: 'title'
},
{
xtype: 'htmleditor',
anchor: '100%',
height: 150,
fieldLabel: 'description',
name: 'description'
}],
buttons: [{
text: 'Add',
handler: function() {
Ext.getCmp('myform').add({
xtype: 'textfield',
fieldLabel: 'Label',
name: 'name'
}).destroy();
}
}]
});
form.render('form');
});
Everything works fine but why I cant add textfield to form with the button?

Thanks for any response and sorry for my bad english :)

mankz
20 Dec 2010, 11:29 AM
You're destroying it right after you add it :) Try:



buttons: [{
text: 'Add',
handler: function() {
form.add(new Ext.form.TextField({
fieldLabel: 'Label',
name: 'name'
});
form.doLayout();
}
}]

kkamis
20 Dec 2010, 2:05 PM
You're destroying it right after you add it :) Try:



buttons: [{
text: 'Add',
handler: function() {
form.add(new Ext.form.TextField({
fieldLabel: 'Label',
name: 'name'
});
form.doLayout();
}
}]



I forgot to delete this function - it was only for testing :) Now its working. Problem was that add function returns object, not a form and form().add().doLayout() doesnt work... Thanks for help :)