PDA

View Full Version : Best way to find form elements



bareflix
5 Dec 2011, 9:23 AM
In my application I have a window which contains a tab panel which contains a form, which may contain fieldsets that hold toggle buttons. Here's an example button:


{
xtype: 'checkboxfield',
margin: '0 10 0 0',
name: 'has_display',
id: 'has_display',
labelAlign: 'right',
boxLabel: 'Display',
handler: this.updateDisplay,
scope: this
},

When updateDisplay is called, it needs to access other buttons to enable and disable them.

I was using this.down ('#otherButton'); to find the other buttons, but this does not work if I have 2 instances of the window.

So what is the best way to get access to a component that is N levels below the window to which I have a reference?

ldonofrio
5 Dec 2011, 10:10 AM
If you have a reference to the actual window you can do winVariable.down('#button'). it will query only de winVariable instance of the window class

bareflix
5 Dec 2011, 11:06 AM
That's what I was doing, but if I have multiple windows up, each editing a different record, that does not work. #button refers to an id, which needs to be globally unique. down finds the first instance of #button, even if it is not below the winVariable.

ldonofrio
5 Dec 2011, 11:17 AM
don't use "id", use "itemId" that is contrained to each instance.

That's what I was doing, but if I have multiple windows up, each editing a different record, that does not work. #button refers to an id, which needs to be globally unique. down finds the first instance of #button, even if it is not below the winVariable.

bareflix
5 Dec 2011, 11:32 AM
I looked at itemId as well, but it only works for the immediate children of the container, according to the documentation. I'd like to be able to re-arrange the form, possibly adding fieldsets or other layout-related intermediates without having to re-code how I access the actual fields.

ldonofrio
5 Dec 2011, 11:44 AM
you don't have to recode anything when updating your layout, simply use win.down(itemId) and not win.child(itemId) and your fields will be there. That's why ComponentQuery is a must (Using cmp.down you are using ComponentQuery)

Just try it!

And forget about absolute ids

bareflix
5 Dec 2011, 12:05 PM
I tried it, and it works! Thanks that's exactly what I was looking for. The documentation for down doesn't mention itemId's. The only references I saw to itemId made it sounds like they only worked for immediate children.