PDA

View Full Version : A problem about the focus of the combo, after load form it always focus on a combo?!



safewolf
3 Jan 2011, 12:18 AM
Hi, i have a problem now

I have a formpanel with comboboxes

but when i open the formpanel
it always focus on the last combox instead of the first item.

and the focused combobox will display it's drop down list also.

Anyone knows how to resolve this?

this is my code:



MyFormPanel = function(){
myStore1 = new Ext.data.JsonStore({
url : url1,
fields : ['id', 'text']
});
myStore1.load();
myStore2 = new Ext.data.JsonStore({
url : url2,
fields : ['id', 'text']
});
myStore2.load();

MyFormPanel.superclass.constructor.call(this, {
title:'My Form',
width : 400,
height: 600,
items:[
{
xtype:'textfield',
name:'field1',
fieldLabel : 'Field1'
},
{
xtype:'combo',
fieldLabel : this.COLUMNS.AGENT_ORGANIZATION.TITLE,
name : this.COLUMNS.AGENT_ORGANIZATION.DATA_INDEX,
hiddenName : "id1",
name:'combo1',
valueField : 'id',
displayField : 'text',
store : myStore1,
triggerAction : 'all',
mode : 'remote',
minChars : 1,
forceSelection : true,
selectOnFocus : true
},
{
xtype:'combo',
fieldLabel : this.COLUMNS.AGENT_ORGANIZATION.TITLE,
name : this.COLUMNS.AGENT_ORGANIZATION.DATA_INDEX,
hiddenName : "id2",
name:'combo2'
valueField : 'id',
displayField : 'text',
store : myStore2,
triggerAction : 'all',
mode : 'remote',
minChars : 1,
forceSelection : true,
selectOnFocus : true
}
]
});
}


Ext.extend(MyFormPanel, Ext.FormPanel, {});



And i overrider the setValue function for the combo to set the value when the store is not loaded:


Ext.override(Ext.form.ComboBox, {
setValue : function(v) {
if (this.hiddenName && this.mode == 'remote'
&& this.store.getCount() <= 0)
this.store.load({
callback : function() {
this.setRawValue(v);
}.createDelegate(this)
});
else {
this.setRawValue(v);
}
return this;
},
setRawValue : function(v) {
var text = v;
if (this.valueField) {
var r = this.findRecord(this.valueField, v);
if (r) {
text = r.data[this.displayField];
} else if (Ext.isDefined(this.valueNotFoundText)) {
text = this.valueNotFoundText;
}
}
this.lastSelectionText = text;
if (this.hiddenField) {
this.hiddenField.value = Ext.value(v, '');
}
Ext.form.ComboBox.superclass.setValue.call(this, text);
this.value = v;
return this;
}
});



i hope that when the combo's value is setted, it will load the store automatically and set the value after the store is loaded.

but, the problem comes!

when i load the form by form.load(), and the form is displayed
the form will focus on the last combobox instead of the first texstfield

Anyone can help me to correct the problem?

skirtle
3 Jan 2011, 8:23 AM
http://www.sencha.com/forum/showthread.php?119984