PDA

View Full Version : Livesearch combo loses focus



bolekstalin1946
20 Aug 2014, 12:40 AM
Hi,

I use ExtJS 4.2 and I've created livesearch combobox. It has store which requests for search suggestions from server side (via proxy with JSON reader) after user writes some letters in combo (I want to achieve something similar to google suggestions). Everything works fine except one problem: when store loads suggestions and list is shown/reloaded (if was visible already), then combobox loses focus and user cannot write anymore. I've tried to set focus manualy (after store load) and it works but there are some 'flashes' when combobox does not have focus and manualy focus-setting wasn't proceeded yet. So when user will press key while this 'flash' then pressed letter is omitted (especially when user uses backspace for delete letters and press backspace key while 'flash' then browser goes to previous page which is terrible). I think that I've write this livesearch combobox exactly like in sencha examples. Am I missing something?
Thanks for help

Here is my livesearch combo:



Ext.define('LiveSearchCombo', {
extend : 'Ext.form.field.ComboBox',


minChars : 1,
triggerAction : 'query',
width: 300,
displayField : 'n',
valueField:'n',
typeAhead : false,
hideTrigger : true,


initComponent: function() {
var me = this;
this.createStore();


this.listeners = {
beforequery:function(queryText) {
queryText.query = encodeURI(queryText.query);
//some store extraparams
}
},


this.callParent(arguments);
},
createStore:function() {
var me = this;
this.store = Ext.create('Ext.data.Store', {
fields: ['n'],
proxy: {
type: 'ajax',
url: '/autocomplete',
reader: {
type: 'json',
root: 'suggestions'
}
}
});
}
});


I've posted this question on stackoverflow, so if someone will be interested here is link: http://stackoverflow.com/questions/25398373/extjs-4-livesearch-combo-loses-focus

Gary Schlosberg
25 Aug 2014, 2:36 PM
With which specific version of ExtJS are you seeing this (e.g. 4.2.1)? Any chance you can post a Fiddle so we can better see what might be going on?
https://fiddle.sencha.com/#home

bolekstalin1946
25 Aug 2014, 10:44 PM
Thanks for answer.
My extjs-all.js contains this part at start:

/*
This file is part of Ext JS 4.2


Copyright (c) 2011-2013 Sencha Inc


Contact: http://www.sencha.com/contact


GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as
published by the Free Software Foundation and appearing in the file LICENSE included in the
packaging of this file.


Please review the following information to ensure the GNU General Public License version 3.0
requirements will be met: http://www.gnu.org/copyleft/gpl.html.


If you are unsure which license is appropriate for your use, please contact the sales department
at http://www.sencha.com/contact.


Build date: 2013-05-16 14:36:50 (f9be68accb407158ba2b1be2c226a6ce1f649314)
*/

I've tried to make Fiddle but I couldn't recreate my bug there. However I will try again to make such Fiddle. If I reproduce my bug in Fiddle then I will post here. Thansk for help

HaddadR
21 Jan 2016, 4:01 AM
Better late than never ;)
add this to your combo :

afterQuery:function(){

this.focus();
}