ComboBox.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-layout-component-field-ComboBox'>/**
  19. </span> * Layout class for {@link Ext.form.field.ComboBox} fields. Handles sizing the input field.
  20. * @private
  21. */
  22. Ext.define('Ext.layout.component.field.ComboBox', {
  23. extend: 'Ext.layout.component.field.Trigger',
  24. alias: 'layout.combobox',
  25. requires: ['Ext.util.TextMetrics'],
  26. type: 'combobox',
  27. startingWidth: null,
  28. getTextWidth: function () {
  29. var me = this,
  30. owner = me.owner,
  31. store = owner.store,
  32. field = owner.displayField,
  33. storeLn = store.data.length,
  34. value = '',
  35. i = 0, n = 0, ln, item, width;
  36. for (; i &lt; storeLn; i++) {
  37. item = store.getAt(i).data[field];
  38. ln = item.length;
  39. // compare the current item's length with the current longest length and store the value
  40. if (ln &gt; n) {
  41. n = ln;
  42. value = item;
  43. }
  44. }
  45. width = Math.max(me.callParent(arguments), owner.inputEl.getTextWidth(value + owner.growAppend));
  46. // it's important to know the starting width else the inputEl could be resized smaller than the boundlist
  47. // NOTE that when removing items from the store that the startingWidth needs to be recalculated
  48. if (!me.startingWidth || owner.removingRecords) {
  49. me.startingWidth = width;
  50. // also, if the width is less than growMin reset the default boundlist width
  51. // or it will appear wider than the component if the trigger is clicked
  52. if (width &lt; owner.growMin) {
  53. owner.defaultListConfig.minWidth = owner.growMin;
  54. }
  55. owner.removingRecords = false;
  56. }
  57. // only resize if the new width is greater than the starting width
  58. return (width &lt; me.startingWidth) ? me.startingWidth : width;
  59. }
  60. });
  61. </pre>
  62. </body>
  63. </html>