PDA

View Full Version : Focus shift on click of enter in search text created as component



kckc1234
10 Sep 2008, 7:58 PM
Hi Everybody,

i have created a search text attached to a grid as a component and used it in my page.
The problem is that i also have buttons in the same page, and when i try to enter some value in the search text and click on enter, the focus goes on to the button and it executes its handler function.

Can you tell me as to why the focus is getting shifted to the button on click of enter button?

The code for the same is as follows:

Ext.namespace('Arrow','Arrow.ux','Arrow.ux.form');

Arrow.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
initComponent : function(){
Arrow.ux.form.SearchField.superclass.initComponent.call(this);
this.on('specialkey', function(f, e){
if(e.getKey() == e.ENTER){
this.onTrigger2Click();
}
}, this);
},

validationEvent:false,
validateOnBlur:false,
trigger1Class:'x-form-clear-trigger',
trigger2Class:'x-form-search-trigger',
hideTrigger1:true,
width:180,
hasSearch : false,
paramName : 'query',

onTrigger1Click : function(){
if(this.hasSearch){
this.el.dom.value = '';
var o = {start: 0};
this.store.baseParams = this.store.baseParams || {};
this.store.baseParams[this.paramName] = '';
this.store.reload({params:o});
this.triggers[0].hide();
this.hasSearch = false;
}
},

onTrigger2Click : function(){
var v = this.getRawValue();
if(v.length < 1){
this.onTrigger1Click();
return;
}
var o = {start: 0};
this.store.baseParams = this.store.baseParams || {};
this.store.baseParams[this.paramName] = v;
this.store.reload({params:o});
this.hasSearch = true;
this.triggers[0].show();
}
});