Created
November 25, 2011 21:37
-
-
Save mitchellsimoens/1394471 to your computer and use it in GitHub Desktop.
Ext.form.field.ComboBox doQuery fix [4.0.7] [4.1.0 PR1]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Mitchell Simoens ([email protected]) | |
* | |
* This override is to make {@link Ext.form.field.ComboBox} not disrupt | |
* existing filters on a {@link Ext.data.Store}. | |
* | |
* This override only affects the {@link Ext.form.field.ComboBox} if | |
* queryMode = 'local' and triggerAction = 'query'. | |
* | |
* Ext JS versions tested: 4.0.7, 4.1.0 PR1, SDK repo (2011-11-25) | |
*/ | |
Ext.override(Ext.form.field.ComboBox, { | |
doQuery: function(queryString, forceAll, rawQuery) { | |
queryString = queryString || ''; | |
// store in object and pass by reference in 'beforequery' | |
// so that client code can modify values. | |
var me = this, | |
qe = { | |
query: queryString, | |
forceAll: forceAll, | |
combo: me, | |
cancel: false | |
}, | |
store = me.store, | |
isLocalMode = me.queryMode === 'local'; | |
if (me.fireEvent('beforequery', qe) === false || qe.cancel) { | |
return false; | |
} | |
// get back out possibly modified values | |
queryString = qe.query; | |
forceAll = qe.forceAll; | |
// query permitted to run | |
if (forceAll || (queryString.length >= me.minChars)) { | |
// expand before starting query so LoadMask can position itself correctly | |
me.expand(); | |
// make sure they aren't querying the same thing | |
if (!me.queryCaching || me.lastQuery !== queryString) { | |
if (isLocalMode) { | |
// forceAll means no filtering - show whole dataset. | |
if (forceAll) { | |
store.clearFilter(); | |
} else { | |
//find the last filter from typeAhead | |
var lastFilter = store.filters.findBy(function(filter) { | |
return filter.property === me.displayField && filter.value === me.lastQuery; | |
}); | |
//if a filter is found, remove it | |
if (lastFilter) { | |
store.filters.remove(lastFilter); | |
} | |
//if queryString is not an empty string, add a filter | |
if (queryString) { | |
store.filter(me.displayField, queryString); | |
} | |
} | |
} else { | |
// Set flag for onLoad handling to know how the Store was loaded | |
me.rawQuery = rawQuery; | |
// In queryMode: 'remote', we assume Store filters are added by the developer as remote filters, | |
// and these are automatically passed as params with every load call, so we do *not* call clearFilter. | |
if (me.pageSize) { | |
// if we're paging, we've changed the query so start at page 1. | |
me.loadPage(1); | |
} else { | |
store.load({ | |
params: me.getParams(queryString) | |
}); | |
} | |
} | |
me.lastQuery = queryString; | |
} | |
// Clear current selection if it does not match the current value in the field | |
if (me.getRawValue() !== me.getDisplayValue()) { | |
me.ignoreSelection++; | |
me.picker.getSelectionModel().deselectAll(); | |
me.ignoreSelection--; | |
} | |
if (isLocalMode) { | |
me.doAutoSelect(); | |
} | |
if (me.typeAhead) { | |
me.doTypeAhead(); | |
} | |
} | |
return true; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment