PDA

View Full Version : focus : add panel item && blur : remove panel item



won.rhee
29 Dec 2011, 9:49 AM
Hello,

So I have two listeners (focus and blur) on a textfield. focus() and blur() listeners will call different controller method.
focus() will create a newpanel, add(newpanel), then doLayout() so that it will be added to currently active panel.
blur() will remove(newpanel) but this does not work.

View


.....
,{
xtype: 'textfield',
width: '255',
placeHolder: 'Near: ZIP,Addrs,or City,State',
id: 'neartextfield',
listeners : {
focus: function(thisfield, e){
Ext.dispatch({
controller: 'StoreCtrl',
action: 'onFocusNear'
})
},
blur: function(thisfield,e){
Ext.dispatch({
controller: 'StoreCtrl',
action: 'onBlurNear'
})
}
}

.....


Controller


....
onFocusNear: function(){
this.newPanel = new Ext.Panel({

layout: 'fit',
html: 'new panel created'

});
this.searchPanel.add(this.newPanel);
this.searchPanel.doLayout()
},
onBlurNear: function(){
//panel with id: "ext-comp-1017"

console.log(this.newPanel);

this.searchPanel.remove(this.newPanel);

//still panel with id: "ext-comp-1017"
console.log(this.newPanel);

}
....


As you can see, I am simply trying to remove an added panel. Is this the correct way of moving an item?
Appreciate any pointers.

mitchellsimoens
29 Dec 2011, 11:28 AM
What isn't working? The focus event not firing? Panel not getting added?

won.rhee
29 Dec 2011, 11:47 AM
focus and blur events do fire as expected and add panel just fine.
It's just that removing that panel doesnt do the trick.

So I remove a panel with
this.searchPanel.remove(this.newPanel); And the very next line, I run
console.log(this.newPanel); still shows same object. Obviously the added panel from focus event still shows.

mitchellsimoens
29 Dec 2011, 11:49 AM
Have you looked at the items of the this.searchPanel? remove(this.newPanel) won't clear the memory of the this.newPanel, you will still need to clean that property up.


delete this.newPanel;

won.rhee
29 Dec 2011, 12:03 PM
thank you again. it worked nicely.