Skip to content

Instantly share code, notes, and snippets.

@jratcliff
Last active July 17, 2020 17:38
Show Gist options
  • Save jratcliff/625c210972eef942d808a9e4bd951516 to your computer and use it in GitHub Desktop.
Save jratcliff/625c210972eef942d808a9e4bd951516 to your computer and use it in GitHub Desktop.
Override that fixes a few things when calculating the min width of a combo's input field.
Ext.define(null, {
override: 'Ext.form.field.ComboBox',
/**
* Override that fixes a few things when calculating the min width of a combo's input field.
*
* First, if a display field is not used but instead a displayTpl, then this override handles that
* Also includes the 'emptyText' in case it is longer than the currently selected text
*/
getGrowWidth: function() {
var me = this;
var value = me.inputEl.dom.value;
var field;
var store;
var dataLn;
var currentLongestLength;
var i;
var item;
var itemLn;
if (me.growToLongestValue) {
field = me.displayField;
store = me.store;
dataLn = store.data.length;
currentLongestLength = 0;
for (i = 0; i < dataLn; i++) {
itemLn = 0; // reinit to 0 for each pass
if (me.displayField) {
item = me.displayTpl.apply(store.getAt(i).data);
} else if (field) {
item = store.getAt(i).data[field];
}
if (item) {
itemLn = item.length;
}
// Compare the current item's length with the current longest length
// and store the value.
if (itemLn > currentLongestLength) {
currentLongestLength = itemLn;
value = item;
}
}
}
// OVERRIDE - BEGIN
// return value;
return value.length < me.emptyText.length ? me.emptyText : value;
// OVERRIDE - END
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment