PDA

View Full Version : Focus event working unexpected



Ercaran
28 May 2009, 5:49 AM
I really can't understand what is my problem about.:-/

I have a function that generates a FieldSet, containing one textfield and 2 radios. I call this function each time I press an "Add button", creating a new FieldSet with its elements and adding it to a FormPanel.
The problem is that each textfield has a focus listener, which creates another listener, and adds it to another element of my application(a treepanel). When I click on treepanel's node, I get the name of the clicked element, and set it as the value of the textfield from which all starts (the one that fires the focus event).
All works. Apart from the fact that EACH field of my FormPanel changes value each time I click the treepanel. I can't figure out why.


var campoAttributo = new Ext.form.FieldSet({
title: 'New attribute',
layout: 'table',
items:[{
xtype: 'textfield',
grow: 'true',
width: 220,
growMin: 220,
growMax: 300,
readOnly: true,
selectOnFocus: false,
listeners:{
focus: function(selectedField){
Ext.getCmp('tree-panel').on('click',function(clickedNode){
var clckdNdName = clickedNode.text;
selectedField.setRawValue(clckdNdName);
});
},
blur: function () { alert('Input Blurred:'+this.id); }
},
emptyText: 'Click a type-node to fill this field'
},{
xtype: 'radio',
name: 'radiofield' + i,
cls: 'radio_button',
boxLabel: '<font color = #14428B size="2"><-in/out-></font>'
},{
xtype: 'radio',
name: 'radiofield'+ i,
checked: true,
cls: 'radio_button',
}],
tools:[{...}]
});//eo campoAttributoAs you can see, focus handler gets from the event the field selected, so I can't really understand why he changes values of ALL the fields. What am I missing?
Thanks a lot.

[edit: ExtJs 3.0 RC1.1, Firefox 3.0.10, Fedora10]

Ercaran
28 May 2009, 9:09 AM
Update --> attempts faliled:

1) add a control like
if(selectedField == this){...my handler...} does not change anything;
2) remove the listener after his first exec (with "un")does not change anything;
3)
single: true does not change anything;
4)
selectedField.events['focus'].clearListeners(); does not change anything;
5)
selectedField.blur() does not change anything;

and so many others I just can't remember...seems like impossible to fix.
I can't even understand what is the point...all listeners running, each one updating its field? no blur after focus event? listener associated to only ONE object, updating all the fields? I've checked every single possibility all the day, that's driving me crazy (and not in the same way Britney Spears sung) {that's what happens when you can't solve smth!! I swear I didn't mean to write it!!! :D}

Anyway...waiting for help...:s

Ercaran
3 Jun 2009, 4:28 AM
self-solved



listeners:{
focus: function changeType(selectedField){
Ext.getCmp('tree-panel').on('click',function(clickedNode){
var clckdNdName = clickedNode.text;
selectedField.setRawValue(clckdNdName);
});
},
blur: function deleteFocusListener(){
Ext.getCmp('tree-panel').purgeListeners();
}


in this way each tree-panel listener exists only when its field has the focus.
Tx to all the guys who helped me!