Search code examples
extjscomboboxextjs4extjs5extjs6

Restrict the user to type more than maxLength extjs Combobox


I have a combobox with a tpl I wanted to restrict the user not to type more than 8 chars. How can I achieve it as combobox doesn't have enforceMaxLength and maxLength only give a tool tip but allows the user to type the characters more than the maxLength. https://fiddle.sencha.com/#view/editor&fiddle/1vam


Solution

  • Ext.form.field.ComboBox derives from Ext.form.field.Text, so for all config options available on the textfield, you can check whether combobox really had to override them in a breaking manner, or whether they are still working. Most of them, if not all, should still be available, even if not part of the combobox documentation.

    As user chrisuae already pointed out in a comment, enforceMaxLength is still working in combobox. This is because combobox does not remove any of the two parts required intact for maxLength to be available, Ext.form.field.Base.fieldSubTpl or Ext.form.field.Text.getSubTplData.

    You may find in the combobox source code that getSubTplData has been overridden, but the line data = me.callParent([fieldData]); means that the original code is still executed.