PDA

View Full Version : refer Component by Name rather than Id



shiva-Kumar
25 Jan 2010, 2:43 AM
Hi,

I need to reference a component by its name rather than its Id .

referece by Id we use Ext.getCmp('IdName');

Similarly do we have any method to reference a component by its name .

Please advice.

Thanks
Shiva

Condor
25 Jan 2010, 3:26 AM
names are not global, so you can only get a field by name starting from a form.

var field = formPanel.getForm().findField('nameOfField');

shiva-Kumar
25 Jan 2010, 4:05 AM
Inside viewport we have layout:'anchor'
now can you tell me how should i refer in this case .



var viewport = new Ext.Viewport({
layout: 'border',
items: [
{
region: 'north',
height: 170,
contentEl: 'north',
frame:false,
border:false
}, {
region: 'south',
contentEl: 'south',
split: true,
height: '15%',
collapsible: true,
title: 'South',
margins: '0 0 0 0'
}, {
region: 'west',
id: 'west-panel',
title: 'Navigation',
split: true,
width: '20%',
collapsible: true,
layout:'accordion',
layoutConfig:{
align:'fit'
},
items:[
{
title:'COB Positions',
id:'PosFilter',
layout: 'anchor',
autoScroll:true,
items:[{
var contrRadio = Ext.form.RadioGroup,{
hideLabel:true,
columns: 2,
anchor: '95%',
items: [
{boxLabel: 'RIC', name: 'contr_rdgrp',id:'cont_rdgrp1', inputValue: 'ric'},
{boxLabel: 'BBG', name: 'contr_rdgrp',id:'cont_rdgrp2', inputValue: 'bbg', checked: true},
{boxLabel: 'Name', name: 'contr_rdgrp',id:'cont_rdgrp3', inputValue: 'contractName'},
{boxLabel: 'Exch Tickr', name: 'contr_rdgrp',id:'cont_rdgrp4', inputValue: 'exchTicker'}
]
}
}]



Requirement is : need to refer the radio field RIC by name "contr_rdgrp" .

Condor
25 Jan 2010, 4:20 AM
But all radios have the same name! You can only distinguish between them using the inputValue.

shiva-Kumar
25 Jan 2010, 4:25 AM
i can rename them as below



items: [
{boxLabel: 'RIC', name: 'contr_rdgrpN1',id:'cont_rdgrp1', inputValue: 'ric'},
{boxLabel: 'BBG', name: 'contr_rdgrpN2',id:'cont_rdgrp2', inputValue: 'bbg', checked: true},
{boxLabel: 'Name', name: 'contr_rdgrpN3',id:'cont_rdgrp3', inputValue: 'contractName'},
{boxLabel: 'Exch Tickr', name: 'contr_rdgrpN4',id:'cont_rdgrp4', inputValue: 'exchTicker'}
]
}
}]

can you advice me in this case.

also hw can we get this using input_value let me know that also please.

Condor
25 Jan 2010, 4:43 AM
You could use:

var field = contrRadio.items.find(function(c){
return c.name == 'contr_rdgrp' && c.inputValue == 'ric';
});
or simply:

var field = contrRadio.items.itemAt(0);
(if it is always the first item)