PDA

View Full Version : loading form data (checkbox & radio) with json



arsenepark
31 Oct 2009, 8:13 AM
Hi, guys
I am trying to load form data (checkbox & raido),
The following is part of my ext code.


{
xtype: 'checkboxgroup',
fieldLabel: 'test 1',
width: 300,
items: [
{boxLabel: 'test 1 1', name: 'dss.test1', checked: true},
{boxLabel: 'test 1 2', name: 'dss.test2', checked: true}
]
}


{
fieldLabel: 'chance',
width: 220,
xtype: 'radiogroup',
items: [
{boxLabel: 'test3 1', name: 'dss.test3', inputValue: 1},
{boxLabel: 'test3 2', name: 'dss.test3', inputValue: 2},
{boxLabel: 'test3 3', name: 'dss.test3', inputValue: 3}
]
}


The following is json response:

{
success: true,
data: {
"dss.test1": "on",
"dss.test2": "on",
"dss.test3": "1"
}
}

But the form just does not load the correct data, while combox always load correctly.
Does anyone know why?

Thanks.
Dennis

arsenepark
31 Oct 2009, 8:46 AM
Besides,
How to set the mapping between the json response and the ext components(like combobox)?
I tried like this:

reader: new Ext.data.JsonReader({
record: 'data',
successProperty: 'success'
}, [
{name: 'dss.test1', mapping: 'test1'},
{name: 'dss.test2', mapping: 'test2'},
{name: 'dss.test3', mapping: 'test3'}
]),
but it does not work out.

Thanks.
Dennis

Animal
1 Nov 2009, 12:29 AM
The XXXGroup fields are fields in their own right with setters.

Drop this page into examples/anywhere



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../ext-all-debug.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
fp = new Ext.FormPanel({
title: 'Test',
style: {
margin: '10px'
},
frame: true,
height: 400,
width: 600,
items: [{
xtype: 'checkboxgroup',
name: 'cbg',
fieldLabel: 'test 1',
width: 300,
items: [
{boxLabel: 'test 1 1', name: 'dss.test1', checked: false},
{boxLabel: 'test 1 2', name: 'dss.test2', checked: false}
]
}, {
xtype: 'radiogroup',
name: 'rg',
fieldLabel: 'chance',
width: 220,
items: [
{boxLabel: 'test3 1', name: 'dss.test3', inputValue: 1},
{boxLabel: 'test3 2', name: 'dss.test3', inputValue: 2},
{boxLabel: 'test3 3', name: 'dss.test3', inputValue: 3}
]
}],
renderTo: document.body
});
f = fp.getForm();
});
</script>
</head>
<body>
</html>


Then try this on the Firebug command line and see the form load:



f.setValues({
cbg: [true, true],
rg: 1
});

arsenepark
1 Nov 2009, 5:13 AM
Thanks,

The checkboxgroup did loaded, but not the radiobox.

Dennis

Animal
1 Nov 2009, 7:04 AM
Maybe you have old code. Because it "worked for me"