PDA

View Full Version : Ext Js 4 Has Many Association form submit values



tmdonalds
30 Apr 2013, 5:35 PM
Need help with accessing has many association fields after form submission. Lets get to the code:

xtype: 'container',

flex: 1, itemId: 'guestContainer', layout: { type: 'column' }, items: [ { xtype: 'fieldcontainer', columnWidth: 0.83, itemId: 'nameContainer0', layout: { align: 'stretch', type: 'hbox' }, items: [ { xtype: 'textfield', flex: 1, cls: 'field-cls', fieldLabel: 'First Name', labelAlign: 'top', name: 'guest[0].firstName' }, { xtype: 'textfield', flex: 0.5, cls: 'field-cls', fieldLabel: 'Middle Initial', labelAlign: 'top', name: 'guest[0].middleInitial' }, { xtype: 'textfield', flex: 1, fieldLabel: 'Last Name', labelAlign: 'top', name: 'guest[0].lastName' }, { xtype: 'textfield', flex: 1, hidden: true, fieldLabel: 'Label', name: 'guest[0].id' } ] }, { xtype: 'checkboxfield', columnWidth: 0.17, itemId: 'chkAddSpouse', margin: '17 0 0 5', labelAlign: 'top', name: 'addSpouse', boxLabel: 'Add Spouse' } ] }, { xtype: 'container', flex: 1, cls: 'topContainerSpacer', itemId: 'spouseContainer', layout: { type: 'column' }, items: [ { xtype: 'fieldcontainer', columnWidth: 0.83, itemId: 'nameContainer1', layout: { align: 'stretch', type: 'hbox' }, items: [ { xtype: 'textfield', flex: 1, cls: 'field-cls', fieldLabel: 'First Name', labelAlign: 'top', name: 'guest[1].firstName' }, { xtype: 'textfield', flex: 0.5, cls: 'field-cls', fieldLabel: 'Middle Initial', labelAlign: 'top', name: 'guest[1].middleInitial' }, { xtype: 'textfield', flex: 1, fieldLabel: 'Last Name', labelAlign: 'top', name: 'guest[1].lastName' }, { xtype: 'textfield', flex: 1, hidden: true, fieldLabel: 'Label', name: 'guest[1].id' } ] }, { xtype: 'button', columnWidth: 0.17, margin: '20 0 0 5', text: 'Remove' } ]
That is how I define my fields for a guest and their spouse. When I want to access the values after submission I get an Uncaught TypeError: Cannot read property '0' of undefined. The value is there but it is having a hard time treating the string as an array. Just to print out the value I am using


var values = form.getValues();
console.log(values.guest[0].firstName);


Any help is greatly appreciated.

tmdonalds
30 Apr 2013, 5:44 PM
Couldn't delete previous POST.
Need help with accessing has many association fields after form submission. Lets get to the code:


items: [
{
xtype: 'container',
flex: 1,
itemId: 'guestContainer',
layout: {
type: 'column'
},
items: [
{
xtype: 'fieldcontainer',
columnWidth: 0.83,
itemId: 'nameContainer0',
layout: {
align: 'stretch',
type: 'hbox'
},
items: [
{
xtype: 'textfield',
flex: 1,
cls: 'field-cls',
fieldLabel: 'First Name',
labelAlign: 'top',
name: 'guest[0].firstName'
},
{
xtype: 'textfield',
flex: 0.5,
cls: 'field-cls',
fieldLabel: 'Middle Initial',
labelAlign: 'top',
name: 'guest[0].middleInitial'
},
{
xtype: 'textfield',
flex: 1,
fieldLabel: 'Last Name',
labelAlign: 'top',
name: 'guest[0].lastName'
},
{
xtype: 'textfield',
flex: 1,
hidden: true,
fieldLabel: 'Label',
name: 'guest[0].id'
}
]
},
{
xtype: 'checkboxfield',
columnWidth: 0.17,
itemId: 'chkAddSpouse',
margin: '17 0 0 5',
labelAlign: 'top',
name: 'addSpouse',
boxLabel: 'Add Spouse'
}
]
},
{
xtype: 'container',
flex: 1,
cls: 'topContainerSpacer',
itemId: 'spouseContainer',
layout: {
type: 'column'
},
items: [
{
xtype: 'fieldcontainer',
columnWidth: 0.83,
itemId: 'nameContainer1',
layout: {
align: 'stretch',
type: 'hbox'
},
items: [
{
xtype: 'textfield',
flex: 1,
cls: 'field-cls',
fieldLabel: 'First Name',
labelAlign: 'top',
name: 'guest[1].firstName'
},
{
xtype: 'textfield',
flex: 0.5,
cls: 'field-cls',
fieldLabel: 'Middle Initial',
labelAlign: 'top',
name: 'guest[1].middleInitial'
},
{
xtype: 'textfield',
flex: 1,
fieldLabel: 'Last Name',
labelAlign: 'top',
name: 'guest[1].lastName'
},
{
xtype: 'textfield',
flex: 1,
hidden: true,
fieldLabel: 'Label',
name: 'guest[1].id'
}
]
},
{
xtype: 'button',
columnWidth: 0.17,
margin: '20 0 0 5',
text: 'Remove'
}
]
}



That is how I define my fields for a guest and their spouse. When I want to access the values after submission I get an Uncaught TypeError: Cannot read property '0' of undefined. The value is there but it is having a hard time treating the string as an array. Just to print out the value I am using


var values = form.getValues();
console.log(values.guest[0].firstName);


Any help is greatly appreciated.