PDA

View Full Version : Radio buttons not checked on form load when your form data json has boolean value



llade
2 Aug 2012, 8:30 AM
form load json:

{
"success":true,
"msg":"",
"data":{
"accountName":"admin",
"enabled":false,
"userId":1
}
}



form extjs code



var saveFormUrl = 'manage/users/update-bean.action';


var editForm = Ext.create("Ext.form.Panel",{
labelWidth: 75,
url:saveFormUrl,
frame:true,
bodyStyle:'padding:5px 5px 0',
height:380,
width: 350,
defaults: {width: 230},
defaultType: 'textfield',


items: [{
name: 'userId',
hidden: true,
hideLabel:true,
allowBlank:false
},
{
fieldLabel: 'Account',
name: 'accountName',
maxLength:20,
minLength:4,
allowBlank:false
},{
fieldLabel: 'Password',
name: 'userPassword',
id: 'userPassword',
maxLength:20,
inputType: 'password',
validator: function(value){
if(value != "" && value.length < 4){
return "At least 4 letters";
}
return true;
}
},{
fieldLabel: 'Comfirm',
id: 'pwd-cfm',
inputType: 'password',
maxLength:20,
//minLength:4,
submitValue: false,//not need to submit
vtype: 'password',
initialPassField: 'userPassword' // id of the initial password field
},{
xtype : 'fieldcontainer',
fieldLabel : 'Status',
defaultType: 'radiofield',
defaults: {
flex: 1
},
layout: 'hbox',
items: [
{
boxLabel : 'Enabled',
name : 'enabled',
checked : true,
inputValue: true,
id : 'radio1'
}, {
boxLabel : 'Disabled',
name : 'enabled',
inputValue: false,
id : 'radio2'
}
]
}
]
});
editForm.on("render",function(cmp){
var config = {
url:'manage/users/load-bean-data.action', //load json
params:{id:'${editId}'},//data base record Pk

};

cmp.getForm().load(config);
});


when you change form load json data boolean value to String like:


{
"success":true,
"msg":"",
"data":{
"accountName":"admin",
"enabled":"false",
"userId":1
}
}


and Radio config:


.....
items: [
{
boxLabel : 'Enabled',
name : 'enabled',
checked : true,
inputValue: 'true',
id : 'radio1'
}, {
boxLabel : 'Disabled',
name : 'enabled',
inputValue: 'false',
id : 'radio2'
}
]


it work ok.

but my problem is :I have to prepare two kinds of json data ,one for grid ,one for form load action。

it is a better way to solve this in convenient?because serialize java bean to json data ,bool value usual be bool value .

reference:
http://www.sencha.com/forum/showthread.php?23998-SOLVED-Radio-buttons-not-checked-on-form-load-doAction