Last active
July 17, 2020 17:38
-
-
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.
This file contains 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
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