Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to access adjacent components / fields

I am looking for a way to access components / field that are either in the same items array as the accessing one or even only in a same parent items array (the last one is just a option).

In ExtJS3 this was easy by simply defining a ref in the owner container but I didn't found anything like that in ExtJS4.

I know that I can use Ext.ComponentQuery() or the shortcuts up() / down() or even Ext.getCmp() but they are all not what I am looking for, cause they just executes a bunch of code while the ref was such an easy Way to do things. Yes, I am aware of the fact that using a ComponentQuery is much more fail safe than the use of hard coded references. But I just want to know if there are some other ways to do this.

like image 533
sra Avatar asked Nov 02 '12 07:11

sra


2 Answers

Alternately, for your case of getting the next element in a container, you can use the nextSibling or prevSibling. All components have these methods. It would be a little less walking around the DOM structure. They also allow for a selector argument.

They are described in the docs here.

like image 115
egerardus Avatar answered Sep 29 '22 12:09

egerardus


Here are some tricks I have used:

//lookup by name
formPanel.getForm().findField('state'); 

//lookup using nextSibling/prevSibling in a fieldset or fieldcontainer
myField.ownerCt.nextSibling('textfield[fieldLabel=Description]')

Here fieldLabel property is used to narrow down field selection but you can use ANY property at all. So if you construct a field with a property ref you can then use it to select your field similar how you would use it in a ComponentQuery .

like image 40
dbrin Avatar answered Sep 29 '22 14:09

dbrin