View Full Version : live search combo results flashing quickly then disappearing

18 Sep 2010, 7:52 PM
I've been using the following example as my reference:


But I've got it almost working except that the results returned from my server are being received, but not shown in the drop-down below the combo box. I can see it appear for a fraction of a second then disappear. I know I'm receiving results because I'm watching them through FireBug in Firefox. I've tried adding/removing all kinds of config options but none seem to change this strange behaviour. I've obviously done something wrong, but haven't a clue what. here's the relevant parts of my ExtJS code:

var resultTpl = new Ext.XTemplate([
'<tpl for="."><div class="search-item">',

var search_store_english = new Ext.data.Store({
url: 'php/search_english.php',
reader: new Ext.data.JsonReader({
root: 'data',
totalProperty: 'number',
idProperty: 'id'
}, vocab_model)

var vocab_model = Ext.data.Record.create([
{name: 'id', type: 'int'},
{name: 'wo', type: 'string'},
{name: 'wp', type: 'string'},
{name: 'al', type: 'string'},
{name: 'ap', type: 'string'},
{name: 'gr', type: 'string'},
{name: 'me', type: 'string'},
{name: 'ty', type: 'string'},
{name: 'er', type: 'int'},
{name: 'se', type: 'string'},
{name: 'da', type: 'date', dateFormat: 'Y-m-d H:i:s'}

xtype: 'combo',
typeAhead: false,
loadingText: 'Searching...',
hideTrigger: true,
width: 500,
pageSize: 5,
itemSelector: 'div.search-item',
displayField: 'wo',
autoSelect: true,
store: search_store_english,
tpl: resultTpl,
mode: 'remote',
onSelect: function(record) {
title: 'Selection',
msg: 'You chose "' + record.data.wo + '"',
buttons: Ext.Msg.OK
}This obviously isn't all the code. There's SO much of it, but these (I hope) are the relevant parts. I can post the PHP if requested, but it shouldn't be the problem, I don't think. Here's the JSON received by the browser for one of the example searches:

{"success":true,"error":0,"message":"","data":[{"id":"125","wo":"aud\u0101ci-a","wp":"audaci-a","al":"ae","ap":"ae","gr":"1f","me":"boldNESS, cockiNESS","ty":"n","er":"2","se":"1","da":"2010-07-17 20:58:00"},{"id":"126","wo":"aud\u0101x","wp":"audax","al":"aud\u0101c-is","ap":"audac-is","gr":"","me":"brave, bold, resolute","ty":"adj","er":"2","se":"1","da":"2010-07-17 20:58:00"}],"number":2}

It's a database of Latin words that I'm searching the "meaning" field (or "me" for short) to find words in English matching the Latin equivalent. E.g., searching for "bold" returns the above two records: "aud?ci-a" and "aud?x".

18 Sep 2010, 10:21 PM
Through a process of elimination I found the cause of the problem: me trying to re-use a data record from elsewhere in my system. If I copy and paste the definition of that record where I'm just referring to the variable "vocab_model", it's working.

Is there a way I can re-use an existing model rather than having to define it in two places to keep the search happy? If not, then I suppose I'll live :-)

18 Sep 2010, 10:58 PM
Of course you should define a record only once!

You don't define multiple classes to encapsulate business objects on your server tier do you?

What's your application's namespace?

18 Sep 2010, 11:52 PM
What's your application's namespace?

Having though about it, I probably don't need so many fields for what I'm planning to do with the live search box, but I'm not sure what you mean about my application's namespace. So far I have one html file with some border layouts, some grids, etc. Not much else, and only a few PHP scripts.