PDA

View Full Version : Combobox restore



MarcinDev
5 Mar 2012, 11:19 AM
Hi,
I have a problem similar to the one from this post: http://www.sencha.com/forum/newreply.php?do=postreply&t=40643
The solution there above works but still it doesn't explain why statesave event gets fired but staterestore doesn't. I'm writing an MVC application and I wanted to process events fired from my combobox in the controller. I've implemented basic getState and applyState functions. When I add listeners directly to my combobox like that:



listeners: {
staterestore: {fn: function(){
log.info('staterestore', this);
}
}


it works as expected, but when I try to add listeners in my controller:


this.control({
'mypane combobox[id=myComboBox]' : {
select : this.onSelect,
staterestore : this.onStateRestore,
statesave : this.onStateSaved
}
}


event staterestore doesn't get fired (select and statesave do work). It's confusing.

mitchellsimoens
5 Mar 2012, 11:37 AM
Does your state get applied?

MarcinDev
5 Mar 2012, 2:23 PM
Yes, it does - the previously selected value gets selected in the combo box, and the listener declared for the combo box gets the event. However the listeners in the controller only get statesaved, but not staterestored.

This is the applyState function from my comboBox:


applyState: function(state)
{
if(state){
Ext.apply(this, state);
}
var selectedValue = state.selectedIndex;//I save the value in the state as selectedIndex
log.info('Preselecting value: ',selectedValue );
this.setValue(selectedValue );
}

softwarezman
23 Mar 2012, 10:34 AM
I am currently running into this issue as well. The controller is not seeing staterestore or beforestaterestore of my combobox. Not sure if this applies to other components but its definitely missing these events. Anybody have any luck getting this to work?

softwarezman
23 Mar 2012, 10:59 AM
Well I tried to get around the problem by firing an application level event but apparently that isn't initialized before the staterestore event so there really isn't appearing to be a way to get that event outside the combobox. Has anybody done this before? It would seem so simple to listen to the staterestore but it's just not working. :-/

softwarezman
2 May 2012, 8:14 AM
I've finally figured this one out (sort of). It's hack-ish but it works. If you fire the staterestore event with the appropriate values (hopefully you would know how to get those) in the afterRender function (THAT is the key to this) then the controller will pick up the event and proceed appropriately. Hope this helps anybody who might still be interested.