PDA

View Full Version : [CLOSED] ComboBox (possibly deeper, Field?) - controller not working as expected



bone
7 Apr 2014, 2:49 PM
Controller hook added in config of class (line 22) will throw error when attempting lookup.

Controller hook added in init of controller (line 12) will work as expected.

Type something in the field to test.


https://fiddle.sencha.com/#fiddle/4sd

evant
7 Apr 2014, 3:05 PM
We need to document this better (pun intended), but you need to specify:



scope: 'this' // yes, the quotes are intended


The reasoning for this is to keep the behaviour of components consistent regardless of how they are nested.

Lets take the following scenario:



Ext.define('SomeComponent', {
extend: 'Ext.Component',
alias: 'widget.some',
listeners: {
click: 'onClick'
},

onClick: function() {}
});


If we have this component outside of any view controller hierarchy, it's all fine and the event fires as we expect. However, we run into a complication if we hit on the "border" case:



{
xtype: 'container',
controller: 'bleh',
items: {
xtype: 'some',
listeners: {
onClick: 'onClick' // Refers to controller.bleh.onClick
}
}
}


By nesting the component in a hierarchy, we change the behaviour in a way the author never intended. Both items are expecting the function to be looked up in a different manner. To remove ambiguity, the default behaviour for a listener is to always look up, unless you specify scope: "this", which means ~never~ look up.


Also note there seems to be some (probably related) issue with onTriggerClick in your test case which needs fixing as well.

bone
8 Apr 2014, 12:11 AM
You are right, the scope: 'this' fixed it.

https://fiddle.sencha.com/#fiddle/4sr
(https://fiddle.sencha.com/#fiddle/4sr)

It makes sense as well.


Also note there seems to be some (probably related) issue with onTriggerClick in your test case which needs fixing as well.

Yes. I've seen it. But in my case I was trying very hard to get rid of the trigger (http://www.sencha.com/forum/showthread.php?283939-ComboBox-hideTrigger-not-working-when-set-in-initComponent), so I didn't care much. Kinda...


Thank you