PDA

View Full Version : How to add a field in the form when a button is clicked



arafat_alam
23 Nov 2011, 3:23 AM
I have a form panel and a button.i want to add a field in the form when the button is clicked..here is the model


Ext.regModel('Contact', {
idProperty: 'id',
fields: [
{ name: 'name', type: 'string' },
{ name: 'phone', type: 'string' },
{ name: 'email', type: 'string' },
{ name: 'address', type: 'string' },
],
validations: [
{ type: 'presence', field: 'name', message: 'Please Enter A Contact Name' },
{ type: 'format', field: 'phone', message: 'Please Enter Phone Number', matcher: /[0-9]/ }
]
});


and here is the form


AddressBook.views.contactEditor = new Ext.form.FormPanel({ id: 'contactEditor',
items: [
{
xtype: 'textfield',
name: 'name',
label: 'Name',
required: true
},
{
xtype: 'textfield',
name: 'phone',
label: 'Phone',
required: true
},
{
xtype: 'emailfield',
name: 'email',
label: 'Email'
},
{
xtype: 'textareafield',
name: 'address',
label: 'Address'
},
],
dockedItems: [
AddressBook.views.contactEditorTopToolbar,
AddressBook.views.contactEditorBottomToolbar,

]
});

i want another phone field in the form when a button is clicked....can any one help..please??

mitchellsimoens
23 Nov 2011, 7:06 AM
You just need to add it via the add() method on the form:


form.add({
xtype : 'textfield',
fieldLabel : 'Phone Number'
});