PDA

View Full Version : Form - Get combo component with hiddenName



Jack_S
18 Mar 2011, 4:35 AM
Hello All,

I have a combobox xtype component in my form with a hiddenName (project_id).
I need to run a filter on the store as this is part of an update form and it should only list the project available tot that customer.

But I can't seem to get the component. I cannot use an id, nor itemId as this form is reused in other modules and I have some overrides.



{border:false
,columnWidth:.33
,layout: 'form'
,baseCls: 'x-plain'
,items: [
{xtype: 'combo-hwd-status',hiddenName:'status_id'}
,{xtype: 'combo-projects', hiddenName:'project_id'}
,{xtype: 'combo-cost-centers', hiddenName:'cost_center_id'}
]
}


How can I get the component and its store in order to run a filter?



var form = Ext.getCmp('array-update-form');

//None of the these methods work
var comboProjects = form.find('project_id');
var comboProjects = form.getForm().findField('project_id');
var comboProjects = form.getComponent('project_id');

comboProjects.store.filter('cid',selectedCustId);


Thanks for any assistance in this matter.

JS

fay
18 Mar 2011, 7:33 AM
Write your own findByHiddenName function? Something (untested) like:



var result = null;

// getForm().items refers to all the fields in/on the form. each() will iterate through them one at a time.
formName.getForm().items.each(function(fld)
{
if (fld.hiddenName) // double-check that there is a hiddenName config/property
{
if (fld.hiddenName == nameToSearchFor)
{
result = fld;
return false; // Stop iterating.
}
}
});

Jack_S
19 Mar 2011, 5:30 AM
Hello Fay,

Thnaks a lot for the suggested function. I've tried to work with it and I still can't get the parent component which in my case is the combo box.

Since my combox xtype are cutom xtype, how could I use this function to access the underlying store?



var cbo = form.findbyType('combo-projects');
//fails
cbo[0].store.filter('cid',selectedCustId);


Thank you

/JS

fay
19 Mar 2011, 6:01 AM
Are you saying that you can't find the combobox using hiddenName (as suggested)? A properly registered xtype wouldn't make a difference in this case.

Jack_S
19 Mar 2011, 6:16 AM
Hello Fay,

Thanks for your help. I troubleshooted my code and found that I was out of context with the component. I had it set the var = comp-id inside a huge on-load function, and was executing the filters outside of this function.

Thanks for helping me. Here is the solution for others trying to access hiddenName items in your form or combobox stores:

All creds to Fay for the function



var comboRacks = null;
var comboProjects = null;
var comboCostCenters = null;
var form = Ext.getCmp('array-update-form');

form.getForm().items.each(function(fld)
{
if (fld.hiddenName) // double-check that there is a hiddenName config/property
{
if (fld.hiddenName == 'rack_id')
{
// alert(fld.getId());
comboRacks= Ext.getCmp(fld.getId());

comboRacks.store.addListener('load', function(){
alert('access load function');
comboRacks.getStore().filter('cid',selectedCustId);
});
}

if (fld.hiddenName == 'project_id')
{
// alert(fld.getId());
comboProjects = Ext.getCmp(fld.getId());

comboProjects.store.addListener('load', function(){
alert('access load function');
comboProjects.getStore().filter('cid',selectedCustId);
});
}

}
});



Thanks /JS