PDA

View Full Version : How to collapse or expand a fieldset when loading data follow the data?



safewolf
1 Apr 2008, 3:10 AM
I hava a formpanel,I want to do like this:
When rending the panel,it will be feed with a json data.In the data,there's a field notifys the panel if need expand a fieldset.
the jason is like this:


{"success":"true","rows":[{"0":"22","id":"4","1":"user2","username":"user2","deafult_number":"1","deafult_email":"1"}]}


and the fieldset is:

{
xtype:'fieldset',
checkboxToggle:true,
checkboxName:'deafult_number',
title: 'Default Mobile',
autoHeight:true,
defaults: {width: 150},
defaultType: 'textfield',
listeners:{'collapse':function(obj){
if(Ext.getCmp('countrycodes')){
Ext.getCmp('countrycodes').allowBlank = true;
Ext.getCmp('mobile_number').allowBlank = true;
}
},
'expand':function(obj){
Ext.getCmp('countrycodes').allowBlank = false;
Ext.getCmp('mobile_number').allowBlank = false;
}
},
collapsed: true,
items :[new Ext.form.ComboBox({
fieldLabel: 'Country Code',
name:'countrycodes',
hiddenName:'mobile_country_code',
id:'countrycodes',
forceSelection: true,
listWidth: 200,
store: new Ext.data.SimpleStore({
fields: ['value', 'text'],
data : CountryCode
}),
valueField:'value',
displayField:'text',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true
})

the fieldset is collapsed usually,but I need it expands when the "deafult_number" equals "1" in the json data

I write like this in the formpanel's code:

form = new Ext.FormPanel({
labelWidth: 180, // label settings here cascade unless overridden
url:'ext_user.php?action=edit',
frame:true,
region:'center',
title : "Add User",
bodyStyle:'padding:5px 5px 0',
width: 430,
reader: new Ext.data.JsonReader
({successProperty: 'success',
root: 'rows'},
[
{name:'id'},
{name:'contact_country_code',mapping:'contact_country_code'},
{name:'contact_mobile_number',mapping:'contact_mobile_number'},
{name:'deafult_number',mapping:'deafult_number'},
{name:'deafult_email',mapping:'deafult_email'}
]),

but it seem to be wrong:(

so poor english,anybody can understand?

hpet
1 Apr 2008, 3:59 AM
If I understand right, you would like your fieldset to be collapsed / expanded if some json data contains a specific value?

If that's the case, I guess you can implement a load event listener for json store. It will fire when json data will be available and then you can check for your value to properly collaps /expand your fieldset. Give your fieldset an ID and use JsonStore for datastore as it will be more simple in your example (already implements reader and everything that goes with the store).



// goes to jsonstore config
listeners: {"load": function() {
if (check for value condition)
Ext.get('myFieldSetID').collapse();
else
Ext.get('myFieldSetID').expand();
}
}