martinrame
19 Feb 2012, 7:33 AM
Hi, I have this form created in Designer:
Ext.define('MyApp.view.ui.CustomerProperties', {
extend: 'Ext.window.Window',
autoRender: false,
height: 288,
width: 421,
layout: {
type: 'fit'
},
title: 'Customer properties',
modal: true,
initComponent: function() {
var me = this;
Ext.applyIf(me, {
dockedItems: [
{
xtype: 'toolbar',
ui: 'footer',
dock: 'bottom',
items: [
{
xtype: 'tbfill'
},
{
xtype: 'button',
id: 'btnOk',
text: 'Ok'
},
{
xtype: 'button',
id: 'btnCancel',
text: 'Cancel'
}
]
}
],
items: [
{
xtype: 'form',
frame: true,
id: 'customerproperties',
bodyPadding: 10,
frameHeader: false,
preventHeader: true,
items: [
{
xtype: 'displayfield',
name: 'id',
fieldLabel: 'Id'
},
{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
anchor: '100%'
},
{
xtype: 'textfield',
name: 'email',
fieldLabel: 'Email',
anchor: '100%'
},
{
xtype: 'numberfield',
name: 'age',
fieldLabel: 'Age',
anchor: '100%'
},
{
xtype: 'checkboxfield',
id: 'active',
name: 'active',
fieldLabel: 'Active',
boxLabel: 'Customer is active',
checked: true,
anchor: '100%'
},
{
xtype: 'radiogroup',
height: 53,
id: 'gender',
layout: {
align: 'stretch',
type: 'vbox'
},
fieldLabel: 'Gender',
allowBlank: false,
columns: 1,
items: [
{
xtype: 'radiofield',
name: 'gender',
value: 'M',
boxLabel: 'Male',
checked: true
},
{
xtype: 'radiofield',
name: 'gender',
value: 'F',
boxLabel: 'Female'
}
]
}
]
}
]
});
me.callParent(arguments);
}
});
To populate form fields, I load a Store using this JSON, then pass a record of it to form's loadRecord:
{
"root": [
{"id": 1, "name": "Robinson, John", "email": "jrobinson@gmail.com", "age":45,"active":true,"gender":"M"},
{"id": 2, "name": "Gonzales, María", "email": "maria.gonzales@aol.com", "age":34,"active":true,"gender":"F"},
{"id": 3, "name": "Smith, Peter", "email": "peter@smithcompany.com", "age":60,"active":false,"gender":"M"}
]
}
But I'm getting this error:
Uncaught TypeError: Cannot use 'in' operator to search for 'gender' in F
I want to set the form's radiogroup named "gender" with the radio "Male" or "Female" checked depending on the value defined in my json.
How I must configure the JSON to do what I want?.
Thanks in advance.
Ext.define('MyApp.view.ui.CustomerProperties', {
extend: 'Ext.window.Window',
autoRender: false,
height: 288,
width: 421,
layout: {
type: 'fit'
},
title: 'Customer properties',
modal: true,
initComponent: function() {
var me = this;
Ext.applyIf(me, {
dockedItems: [
{
xtype: 'toolbar',
ui: 'footer',
dock: 'bottom',
items: [
{
xtype: 'tbfill'
},
{
xtype: 'button',
id: 'btnOk',
text: 'Ok'
},
{
xtype: 'button',
id: 'btnCancel',
text: 'Cancel'
}
]
}
],
items: [
{
xtype: 'form',
frame: true,
id: 'customerproperties',
bodyPadding: 10,
frameHeader: false,
preventHeader: true,
items: [
{
xtype: 'displayfield',
name: 'id',
fieldLabel: 'Id'
},
{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
anchor: '100%'
},
{
xtype: 'textfield',
name: 'email',
fieldLabel: 'Email',
anchor: '100%'
},
{
xtype: 'numberfield',
name: 'age',
fieldLabel: 'Age',
anchor: '100%'
},
{
xtype: 'checkboxfield',
id: 'active',
name: 'active',
fieldLabel: 'Active',
boxLabel: 'Customer is active',
checked: true,
anchor: '100%'
},
{
xtype: 'radiogroup',
height: 53,
id: 'gender',
layout: {
align: 'stretch',
type: 'vbox'
},
fieldLabel: 'Gender',
allowBlank: false,
columns: 1,
items: [
{
xtype: 'radiofield',
name: 'gender',
value: 'M',
boxLabel: 'Male',
checked: true
},
{
xtype: 'radiofield',
name: 'gender',
value: 'F',
boxLabel: 'Female'
}
]
}
]
}
]
});
me.callParent(arguments);
}
});
To populate form fields, I load a Store using this JSON, then pass a record of it to form's loadRecord:
{
"root": [
{"id": 1, "name": "Robinson, John", "email": "jrobinson@gmail.com", "age":45,"active":true,"gender":"M"},
{"id": 2, "name": "Gonzales, María", "email": "maria.gonzales@aol.com", "age":34,"active":true,"gender":"F"},
{"id": 3, "name": "Smith, Peter", "email": "peter@smithcompany.com", "age":60,"active":false,"gender":"M"}
]
}
But I'm getting this error:
Uncaught TypeError: Cannot use 'in' operator to search for 'gender' in F
I want to set the form's radiogroup named "gender" with the radio "Male" or "Female" checked depending on the value defined in my json.
How I must configure the JSON to do what I want?.
Thanks in advance.