PDA

View Full Version : the result for a loaded combobox doesn't display



flamant
8 Aug 2010, 7:03 AM
Hi,
I coded a combobox that used to work.
Here is the code



var foundProtocolRecord = Ext.data.Record.create([
{name: 'id'},
{name: 'alias'}
]);


var protocolSearchDataStore = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: '<c:url value="/secure/getProtocolList.htm"/>'

}),
reader: new Ext.data.JsonReader({
root: 'rows',
totalProperty: 'totalCount',
id: 'id'
}, foundProtocolRecord
),
sortInfo: {
field: 'alias',
direction: 'ASC'
}
});

var protocolSearchResultTemplate = new Ext.XTemplate(
'<tpl for="."><div class="search-item">',
'<h3><img src="<c:url value="/img/study.gif"/>"/> <spring:message code="dataEntryMgmt.alias"/>{alias}</h3><br />',
'<i><spring:message code="dataEntryMgmt.protocolId"/>{id}</i>',
'</div></tpl>'
);

new Ext.form.ComboBox({
id: 'protocolSearch',
name: 'protocolSearch',
hideLabel: true,
store: protocolSearchDataStore,
displayField:'alias',
typeAhead: false,
loadingText: '<spring:message code="dataEntryMgmt.protocolSearchLoadText"/>',
width: 175,
minChars: 3,
hideTrigger:true,
tpl: protocolSearchResultTemplate,
itemSelector: 'div.search-item',
/*select: function(combo, record, index) {*/
onSelect: function(record){
this.setValue(record.data.alias+" ("+record.data.id+")");
Ext.getCmp("centerSearch").store.baseParams = { protocolId: record.data.id };
this.collapse();
},
onFocus: function(){
this.reset();
Ext.getCmp("centerSearch").reset();
Ext.getCmp("subjectTreeView").root.removeAll();
Ext.getCmp("findASubject").reset();
}
}),


The combobox doesn't display any result any more. I checked the request in firebug : it works fine. I checked that the server code part (in java) works fine. I haven't any error displayed but no results are displayed. I don't understand why because it used to work. I only added the onFocus event handler. Thank you for your help.

pmatsumura
8 Aug 2010, 8:40 AM
What happens, when you remove

this.reset();
?

flamant
8 Aug 2010, 8:52 AM
Thank you for your answer,

Unfortunately, nothing is changing when I remove



this.reset();


or


this.reset();
Ext.getCmp("centerSearch").reset();
Ext.getCmp("subjectTreeView").root.removeAll();
Ext.getCmp("findASubject").reset();

flamant
8 Aug 2010, 8:59 AM
Sorry when I remove completely the onFocus event handler it works !
How can I manage it differently ?

pmatsumura
8 Aug 2010, 10:38 AM
Try using the "on" method of the combo box or define the focus event handler using the listener config instead of the onFocus method.

Here's a the link to the combo box documentation -> http://dev.sencha.com/deploy/dev/docs/?class=Ext.form.ComboBox

Condor
8 Aug 2010, 10:38 PM
I agree. Do not override onSelect or onFocus. Use the 'select' and 'focus' events instead.

(there is still some old Ext v1 code floating around that used onSelect, but on newer versions you really shouldn't use that)

flamant
20 Aug 2010, 7:14 AM
Thank you for your answers. I used the select and focus event