PDA

View Full Version : build the name config to reuse form



AssetWorks
10 Oct 2013, 6:46 AM
I have an address class that I want to reuse. but I want to build the name in each field to have a prefix and so when I call that xtype I want to be able to pass in this prefix so that each time it matches the field.


Ext.define('myForm',{
extends:'Ext.form.Panel',
prefix:'ShippingAddress', //<--------I want to define my prefix here
alias:'widget.myform',
items:[
{xtype: 'textfield', name: {prefix}+'Line1'},
{xtype: 'textfield', name: {prefix}+'City'},
{xtype: 'textfield', name: {prefix}+'State'}
// .....etc...
});

so I can do this later:


....
xtype: 'myform',
prefix: 'BillingAddress'

ettavolt
10 Oct 2013, 7:30 AM
This is possible (you need to define items in initComponent method), but I advise to factor out address to a separate entity and then have a collection of them/ several hasOne associations.