Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1368 lines
53 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.form.ComboBox"></div>/**
  16. * @class Ext.form.ComboBox
  17. * @extends Ext.form.TriggerField
  18. * <p>A combobox control with support for autocomplete, remote-loading, paging and many other features.</p>
  19. * <p>A ComboBox works in a similar manner to a traditional HTML &lt;select> field. The difference is
  20. * that to submit the {@link #valueField}, you must specify a {@link #hiddenName} to create a hidden input
  21. * field to hold the value of the valueField. The <i>{@link #displayField}</i> is shown in the text field
  22. * which is named according to the {@link #name}.</p>
  23. * <p><b><u>Events</u></b></p>
  24. * <p>To do something when something in ComboBox is selected, configure the select event:<pre><code>
  25. var cb = new Ext.form.ComboBox({
  26. // all of your config options
  27. listeners:{
  28. scope: yourScope,
  29. 'select': yourFunction
  30. }
  31. });
  32. // Alternatively, you can assign events after the object is created:
  33. var cb = new Ext.form.ComboBox(yourOptions);
  34. cb.on('select', yourFunction, yourScope);
  35. * </code></pre></p>
  36. *
  37. * <p><b><u>ComboBox in Grid</u></b></p>
  38. * <p>If using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a {@link Ext.grid.Column#renderer renderer}
  39. * will be needed to show the displayField when the editor is not active. Set up the renderer manually, or implement
  40. * a reusable render, for example:<pre><code>
  41. // create reusable renderer
  42. Ext.util.Format.comboRenderer = function(combo){
  43. return function(value){
  44. var record = combo.findRecord(combo.{@link #valueField}, value);
  45. return record ? record.get(combo.{@link #displayField}) : combo.{@link #valueNotFoundText};
  46. }
  47. }
  48. // create the combo instance
  49. var combo = new Ext.form.ComboBox({
  50. {@link #typeAhead}: true,
  51. {@link #triggerAction}: 'all',
  52. {@link #lazyRender}:true,
  53. {@link #mode}: 'local',
  54. {@link #store}: new Ext.data.ArrayStore({
  55. id: 0,
  56. fields: [
  57. 'myId',
  58. 'displayText'
  59. ],
  60. data: [[1, 'item1'], [2, 'item2']]
  61. }),
  62. {@link #valueField}: 'myId',
  63. {@link #displayField}: 'displayText'
  64. });
  65. // snippet of column model used within grid
  66. var cm = new Ext.grid.ColumnModel([{
  67. ...
  68. },{
  69. header: "Some Header",
  70. dataIndex: 'whatever',
  71. width: 130,
  72. editor: combo, // specify reference to combo instance
  73. renderer: Ext.util.Format.comboRenderer(combo) // pass combo instance to reusable renderer
  74. },
  75. ...
  76. ]);
  77. * </code></pre></p>
  78. *
  79. * <p><b><u>Filtering</u></b></p>
  80. * <p>A ComboBox {@link #doQuery uses filtering itself}, for information about filtering the ComboBox
  81. * store manually see <tt>{@link #lastQuery}</tt>.</p>
  82. * @constructor
  83. * Create a new ComboBox.
  84. * @param {Object} config Configuration options
  85. * @xtype combo
  86. */
  87. Ext.form.ComboBox = Ext.extend(Ext.form.TriggerField, {
  88. <div id="cfg-Ext.form.ComboBox-transform"></div>/**
  89. * @cfg {Mixed} transform The id, DOM node or element of an existing HTML SELECT to convert to a ComboBox.
  90. * Note that if you specify this and the combo is going to be in an {@link Ext.form.BasicForm} or
  91. * {@link Ext.form.FormPanel}, you must also set <tt>{@link #lazyRender} = true</tt>.
  92. */
  93. <div id="cfg-Ext.form.ComboBox-lazyRender"></div>/**
  94. * @cfg {Boolean} lazyRender <tt>true</tt> to prevent the ComboBox from rendering until requested
  95. * (should always be used when rendering into an {@link Ext.Editor} (e.g. {@link Ext.grid.EditorGridPanel Grids}),
  96. * defaults to <tt>false</tt>).
  97. */
  98. <div id="cfg-Ext.form.ComboBox-autoCreate"></div>/**
  99. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or <tt>true</tt> for a default
  100. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  101. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  102. * <pre><code>{tag: "input", type: "text", size: "24", autocomplete: "off"}</code></pre>
  103. */
  104. <div id="cfg-Ext.form.ComboBox-store"></div>/**
  105. * @cfg {Ext.data.Store/Array} store The data source to which this combo is bound (defaults to <tt>undefined</tt>).
  106. * Acceptable values for this property are:
  107. * <div class="mdetail-params"><ul>
  108. * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
  109. * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally,
  110. * automatically generating {@link Ext.data.Field#name field names} to work with all data components.
  111. * <div class="mdetail-params"><ul>
  112. * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
  113. * A 1-dimensional array will automatically be expanded (each array item will be used for both the combo
  114. * {@link #valueField} and {@link #displayField})</div></li>
  115. * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
  116. * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
  117. * {@link #valueField}, while the value at index 1 is assumed to be the combo {@link #displayField}.
  118. * </div></li></ul></div></li></ul></div>
  119. * <p>See also <tt>{@link #mode}</tt>.</p>
  120. */
  121. <div id="cfg-Ext.form.ComboBox-title"></div>/**
  122. * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
  123. * the dropdown list (defaults to undefined, with no header element)
  124. */
  125. // private
  126. defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
  127. <div id="cfg-Ext.form.ComboBox-listWidth"></div>/**
  128. * @cfg {Number} listWidth The width (used as a parameter to {@link Ext.Element#setWidth}) of the dropdown
  129. * list (defaults to the width of the ComboBox field). See also <tt>{@link #minListWidth}
  130. */
  131. <div id="cfg-Ext.form.ComboBox-displayField"></div>/**
  132. * @cfg {String} displayField The underlying {@link Ext.data.Field#name data field name} to bind to this
  133. * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'field1'</tt> if
  134. * {@link #transform transforming a select} or if the {@link #store field name is autogenerated based on
  135. * the store configuration}).
  136. * <p>See also <tt>{@link #valueField}</tt>.</p>
  137. * <p><b>Note</b>: if using a ComboBox in an {@link Ext.grid.EditorGridPanel Editor Grid} a
  138. * {@link Ext.grid.Column#renderer renderer} will be needed to show the displayField when the editor is not
  139. * active.</p>
  140. */
  141. <div id="cfg-Ext.form.ComboBox-valueField"></div>/**
  142. * @cfg {String} valueField The underlying {@link Ext.data.Field#name data value name} to bind to this
  143. * ComboBox (defaults to undefined if <tt>{@link #mode} = 'remote'</tt> or <tt>'field2'</tt> if
  144. * {@link #transform transforming a select} or if the {@link #store field name is autogenerated based on
  145. * the store configuration}).
  146. * <p><b>Note</b>: use of a <tt>valueField</tt> requires the user to make a selection in order for a value to be
  147. * mapped. See also <tt>{@link #hiddenName}</tt>, <tt>{@link #hiddenValue}</tt>, and <tt>{@link #displayField}</tt>.</p>
  148. */
  149. <div id="cfg-Ext.form.ComboBox-hiddenName"></div>/**
  150. * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
  151. * field's data value (defaults to the underlying DOM element's name). Required for the combo's value to automatically
  152. * post during a form submission. See also {@link #valueField}.
  153. */
  154. <div id="cfg-Ext.form.ComboBox-hiddenId"></div>/**
  155. * @cfg {String} hiddenId If <tt>{@link #hiddenName}</tt> is specified, <tt>hiddenId</tt> can also be provided
  156. * to give the hidden field a unique id. The <tt>hiddenId</tt> and combo {@link Ext.Component#id id} should be
  157. * different, since no two DOM nodes should share the same id.
  158. */
  159. <div id="cfg-Ext.form.ComboBox-hiddenValue"></div>/**
  160. * @cfg {String} hiddenValue Sets the initial value of the hidden field if {@link #hiddenName} is
  161. * specified to contain the selected {@link #valueField}, from the Store. Defaults to the configured
  162. * <tt>{@link Ext.form.Field#value value}</tt>.
  163. */
  164. <div id="cfg-Ext.form.ComboBox-listClass"></div>/**
  165. * @cfg {String} listClass The CSS class to add to the predefined <tt>'x-combo-list'</tt> class
  166. * applied the dropdown list element (defaults to '').
  167. */
  168. listClass : '',
  169. <div id="cfg-Ext.form.ComboBox-selectedClass"></div>/**
  170. * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list
  171. * (defaults to <tt>'x-combo-selected'</tt>)
  172. */
  173. selectedClass : 'x-combo-selected',
  174. <div id="cfg-Ext.form.ComboBox-listEmptyText"></div>/**
  175. * @cfg {String} listEmptyText The empty text to display in the data view if no items are found.
  176. * (defaults to '')
  177. */
  178. listEmptyText: '',
  179. <div id="cfg-Ext.form.ComboBox-triggerClass"></div>/**
  180. * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always
  181. * get the class <tt>'x-form-trigger'</tt> and <tt>triggerClass</tt> will be <b>appended</b> if specified
  182. * (defaults to <tt>'x-form-arrow-trigger'</tt> which displays a downward arrow icon).
  183. */
  184. triggerClass : 'x-form-arrow-trigger',
  185. <div id="cfg-Ext.form.ComboBox-shadow"></div>/**
  186. * @cfg {Boolean/String} shadow <tt>true</tt> or <tt>"sides"</tt> for the default effect, <tt>"frame"</tt> for
  187. * 4-way shadow, and <tt>"drop"</tt> for bottom-right
  188. */
  189. shadow : 'sides',
  190. <div id="cfg-Ext.form.ComboBox-listAlign"></div>/**
  191. * @cfg {String/Array} listAlign A valid anchor position value. See <tt>{@link Ext.Element#alignTo}</tt> for details
  192. * on supported anchor positions and offsets. To specify x/y offsets as well, this value
  193. * may be specified as an Array of <tt>{@link Ext.Element#alignTo}</tt> method arguments.</p>
  194. * <pre><code>[ 'tl-bl?', [6,0] ]</code></pre>(defaults to <tt>'tl-bl?'</tt>)
  195. */
  196. listAlign : 'tl-bl?',
  197. <div id="cfg-Ext.form.ComboBox-maxHeight"></div>/**
  198. * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown
  199. * (defaults to <tt>300</tt>)
  200. */
  201. maxHeight : 300,
  202. <div id="cfg-Ext.form.ComboBox-minHeight"></div>/**
  203. * @cfg {Number} minHeight The minimum height in pixels of the dropdown list when the list is constrained by its
  204. * distance to the viewport edges (defaults to <tt>90</tt>)
  205. */
  206. minHeight : 90,
  207. <div id="cfg-Ext.form.ComboBox-triggerAction"></div>/**
  208. * @cfg {String} triggerAction The action to execute when the trigger is clicked.
  209. * <div class="mdetail-params"><ul>
  210. * <li><b><tt>'query'</tt></b> : <b>Default</b>
  211. * <p class="sub-desc">{@link #doQuery run the query} using the {@link Ext.form.Field#getRawValue raw value}.</p></li>
  212. * <li><b><tt>'all'</tt></b> :
  213. * <p class="sub-desc">{@link #doQuery run the query} specified by the <tt>{@link #allQuery}</tt> config option</p></li>
  214. * </ul></div>
  215. * <p>See also <code>{@link #queryParam}</code>.</p>
  216. */
  217. triggerAction : 'query',
  218. <div id="cfg-Ext.form.ComboBox-minChars"></div>/**
  219. * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and
  220. * {@link #typeAhead} activate (defaults to <tt>4</tt> if <tt>{@link #mode} = 'remote'</tt> or <tt>0</tt> if
  221. * <tt>{@link #mode} = 'local'</tt>, does not apply if
  222. * <tt>{@link Ext.form.TriggerField#editable editable} = false</tt>).
  223. */
  224. minChars : 4,
  225. <div id="cfg-Ext.form.ComboBox-autoSelect"></div>/**
  226. * @cfg {Boolean} autoSelect <tt>true</tt> to select the first result gathered by the data store (defaults
  227. * to <tt>true</tt>). A false value would require a manual selection from the dropdown list to set the components value
  228. * unless the value of ({@link #typeAheadDelay}) were true.
  229. */
  230. autoSelect : true,
  231. <div id="cfg-Ext.form.ComboBox-typeAhead"></div>/**
  232. * @cfg {Boolean} typeAhead <tt>true</tt> to populate and autoselect the remainder of the text being
  233. * typed after a configurable delay ({@link #typeAheadDelay}) if it matches a known value (defaults
  234. * to <tt>false</tt>)
  235. */
  236. typeAhead : false,
  237. <div id="cfg-Ext.form.ComboBox-queryDelay"></div>/**
  238. * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and
  239. * sending the query to filter the dropdown list (defaults to <tt>500</tt> if <tt>{@link #mode} = 'remote'</tt>
  240. * or <tt>10</tt> if <tt>{@link #mode} = 'local'</tt>)
  241. */
  242. queryDelay : 500,
  243. <div id="cfg-Ext.form.ComboBox-pageSize"></div>/**
  244. * @cfg {Number} pageSize If greater than <tt>0</tt>, a {@link Ext.PagingToolbar} is displayed in the
  245. * footer of the dropdown list and the {@link #doQuery filter queries} will execute with page start and
  246. * {@link Ext.PagingToolbar#pageSize limit} parameters. Only applies when <tt>{@link #mode} = 'remote'</tt>
  247. * (defaults to <tt>0</tt>).
  248. */
  249. pageSize : 0,
  250. <div id="cfg-Ext.form.ComboBox-selectOnFocus"></div>/**
  251. * @cfg {Boolean} selectOnFocus <tt>true</tt> to select any existing text in the field immediately on focus.
  252. * Only applies when <tt>{@link Ext.form.TriggerField#editable editable} = true</tt> (defaults to
  253. * <tt>false</tt>).
  254. */
  255. selectOnFocus : false,
  256. <div id="cfg-Ext.form.ComboBox-queryParam"></div>/**
  257. * @cfg {String} queryParam Name of the query ({@link Ext.data.Store#baseParam baseParam} name for the store)
  258. * as it will be passed on the querystring (defaults to <tt>'query'</tt>)
  259. */
  260. queryParam : 'query',
  261. <div id="cfg-Ext.form.ComboBox-loadingText"></div>/**
  262. * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
  263. * when <tt>{@link #mode} = 'remote'</tt> (defaults to <tt>'Loading...'</tt>)
  264. */
  265. loadingText : 'Loading...',
  266. <div id="cfg-Ext.form.ComboBox-resizable"></div>/**
  267. * @cfg {Boolean} resizable <tt>true</tt> to add a resize handle to the bottom of the dropdown list
  268. * (creates an {@link Ext.Resizable} with 'se' {@link Ext.Resizable#pinned pinned} handles).
  269. * Defaults to <tt>false</tt>.
  270. */
  271. resizable : false,
  272. <div id="cfg-Ext.form.ComboBox-handleHeight"></div>/**
  273. * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if
  274. * <tt>{@link #resizable} = true</tt> (defaults to <tt>8</tt>)
  275. */
  276. handleHeight : 8,
  277. <div id="cfg-Ext.form.ComboBox-allQuery"></div>/**
  278. * @cfg {String} allQuery The text query to send to the server to return all records for the list
  279. * with no filtering (defaults to '')
  280. */
  281. allQuery: '',
  282. <div id="cfg-Ext.form.ComboBox-mode"></div>/**
  283. * @cfg {String} mode Acceptable values are:
  284. * <div class="mdetail-params"><ul>
  285. * <li><b><tt>'remote'</tt></b> : <b>Default</b>
  286. * <p class="sub-desc">Automatically loads the <tt>{@link #store}</tt> the <b>first</b> time the trigger
  287. * is clicked. If you do not want the store to be automatically loaded the first time the trigger is
  288. * clicked, set to <tt>'local'</tt> and manually load the store. To force a requery of the store
  289. * <b>every</b> time the trigger is clicked see <tt>{@link #lastQuery}</tt>.</p></li>
  290. * <li><b><tt>'local'</tt></b> :
  291. * <p class="sub-desc">ComboBox loads local data</p>
  292. * <pre><code>
  293. var combo = new Ext.form.ComboBox({
  294. renderTo: document.body,
  295. mode: 'local',
  296. store: new Ext.data.ArrayStore({
  297. id: 0,
  298. fields: [
  299. 'myId', // numeric value is the key
  300. 'displayText'
  301. ],
  302. data: [[1, 'item1'], [2, 'item2']] // data is local
  303. }),
  304. valueField: 'myId',
  305. displayField: 'displayText',
  306. triggerAction: 'all'
  307. });
  308. * </code></pre></li>
  309. * </ul></div>
  310. */
  311. mode: 'remote',
  312. <div id="cfg-Ext.form.ComboBox-minListWidth"></div>/**
  313. * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to <tt>70</tt>, will
  314. * be ignored if <tt>{@link #listWidth}</tt> has a higher value)
  315. */
  316. minListWidth : 70,
  317. <div id="cfg-Ext.form.ComboBox-forceSelection"></div>/**
  318. * @cfg {Boolean} forceSelection <tt>true</tt> to restrict the selected value to one of the values in the list,
  319. * <tt>false</tt> to allow the user to set arbitrary text into the field (defaults to <tt>false</tt>)
  320. */
  321. forceSelection : false,
  322. <div id="cfg-Ext.form.ComboBox-typeAheadDelay"></div>/**
  323. * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
  324. * if <tt>{@link #typeAhead} = true</tt> (defaults to <tt>250</tt>)
  325. */
  326. typeAheadDelay : 250,
  327. <div id="cfg-Ext.form.ComboBox-valueNotFoundText"></div>/**
  328. * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
  329. * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined). If this
  330. * default text is used, it means there is no value set and no validation will occur on this field.
  331. */
  332. <div id="cfg-Ext.form.ComboBox-lazyInit"></div>/**
  333. * @cfg {Boolean} lazyInit <tt>true</tt> to not initialize the list for this combo until the field is focused
  334. * (defaults to <tt>true</tt>)
  335. */
  336. lazyInit : true,
  337. <div id="cfg-Ext.form.ComboBox-clearFilterOnReset"></div>/**
  338. * @cfg {Boolean} clearFilterOnReset <tt>true</tt> to clear any filters on the store (when in local mode) when reset is called
  339. * (defaults to <tt>true</tt>)
  340. */
  341. clearFilterOnReset : true,
  342. <div id="cfg-Ext.form.ComboBox-submitValue"></div>/**
  343. * @cfg {Boolean} submitValue False to clear the name attribute on the field so that it is not submitted during a form post.
  344. * If a hiddenName is specified, setting this to true will cause both the hidden field and the element to be submitted.
  345. * Defaults to <tt>undefined</tt>.
  346. */
  347. submitValue: undefined,
  348. <div id="prop-Ext.form.ComboBox-lastQuery"></div>/**
  349. * The value of the match string used to filter the store. Delete this property to force a requery.
  350. * Example use:
  351. * <pre><code>
  352. var combo = new Ext.form.ComboBox({
  353. ...
  354. mode: 'remote',
  355. ...
  356. listeners: {
  357. // delete the previous query in the beforequery event or set
  358. // combo.lastQuery = null (this will reload the store the next time it expands)
  359. beforequery: function(qe){
  360. delete qe.combo.lastQuery;
  361. }
  362. }
  363. });
  364. * </code></pre>
  365. * To make sure the filter in the store is not cleared the first time the ComboBox trigger is used
  366. * configure the combo with <tt>lastQuery=''</tt>. Example use:
  367. * <pre><code>
  368. var combo = new Ext.form.ComboBox({
  369. ...
  370. mode: 'local',
  371. triggerAction: 'all',
  372. lastQuery: ''
  373. });
  374. * </code></pre>
  375. * @property lastQuery
  376. * @type String
  377. */
  378. // private
  379. initComponent : function(){
  380. Ext.form.ComboBox.superclass.initComponent.call(this);
  381. this.addEvents(
  382. <div id="event-Ext.form.ComboBox-expand"></div>/**
  383. * @event expand
  384. * Fires when the dropdown list is expanded
  385. * @param {Ext.form.ComboBox} combo This combo box
  386. */
  387. 'expand',
  388. <div id="event-Ext.form.ComboBox-collapse"></div>/**
  389. * @event collapse
  390. * Fires when the dropdown list is collapsed
  391. * @param {Ext.form.ComboBox} combo This combo box
  392. */
  393. 'collapse',
  394. <div id="event-Ext.form.ComboBox-beforeselect"></div>/**
  395. * @event beforeselect
  396. * Fires before a list item is selected. Return false to cancel the selection.
  397. * @param {Ext.form.ComboBox} combo This combo box
  398. * @param {Ext.data.Record} record The data record returned from the underlying store
  399. * @param {Number} index The index of the selected item in the dropdown list
  400. */
  401. 'beforeselect',
  402. <div id="event-Ext.form.ComboBox-select"></div>/**
  403. * @event select
  404. * Fires when a list item is selected
  405. * @param {Ext.form.ComboBox} combo This combo box
  406. * @param {Ext.data.Record} record The data record returned from the underlying store
  407. * @param {Number} index The index of the selected item in the dropdown list
  408. */
  409. 'select',
  410. <div id="event-Ext.form.ComboBox-beforequery"></div>/**
  411. * @event beforequery
  412. * Fires before all queries are processed. Return false to cancel the query or set the queryEvent's
  413. * cancel property to true.
  414. * @param {Object} queryEvent An object that has these properties:<ul>
  415. * <li><code>combo</code> : Ext.form.ComboBox <div class="sub-desc">This combo box</div></li>
  416. * <li><code>query</code> : String <div class="sub-desc">The query</div></li>
  417. * <li><code>forceAll</code> : Boolean <div class="sub-desc">True to force "all" query</div></li>
  418. * <li><code>cancel</code> : Boolean <div class="sub-desc">Set to true to cancel the query</div></li>
  419. * </ul>
  420. */
  421. 'beforequery'
  422. );
  423. if(this.transform){
  424. var s = Ext.getDom(this.transform);
  425. if(!this.hiddenName){
  426. this.hiddenName = s.name;
  427. }
  428. if(!this.store){
  429. this.mode = 'local';
  430. var d = [], opts = s.options;
  431. for(var i = 0, len = opts.length;i < len; i++){
  432. var o = opts[i],
  433. value = (o.hasAttribute ? o.hasAttribute('value') : o.getAttributeNode('value').specified) ? o.value : o.text;
  434. if(o.selected && Ext.isEmpty(this.value, true)) {
  435. this.value = value;
  436. }
  437. d.push([value, o.text]);
  438. }
  439. this.store = new Ext.data.ArrayStore({
  440. idIndex: 0,
  441. fields: ['value', 'text'],
  442. data : d,
  443. autoDestroy: true
  444. });
  445. this.valueField = 'value';
  446. this.displayField = 'text';
  447. }
  448. s.name = Ext.id(); // wipe out the name in case somewhere else they have a reference
  449. if(!this.lazyRender){
  450. this.target = true;
  451. this.el = Ext.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
  452. this.render(this.el.parentNode, s);
  453. }
  454. Ext.removeNode(s);
  455. }
  456. //auto-configure store from local array data
  457. else if(this.store){
  458. this.store = Ext.StoreMgr.lookup(this.store);
  459. if(this.store.autoCreated){
  460. this.displayField = this.valueField = 'field1';
  461. if(!this.store.expandData){
  462. this.displayField = 'field2';
  463. }
  464. this.mode = 'local';
  465. }
  466. }
  467. this.selectedIndex = -1;
  468. if(this.mode == 'local'){
  469. if(!Ext.isDefined(this.initialConfig.queryDelay)){
  470. this.queryDelay = 10;
  471. }
  472. if(!Ext.isDefined(this.initialConfig.minChars)){
  473. this.minChars = 0;
  474. }
  475. }
  476. },
  477. // private
  478. onRender : function(ct, position){
  479. if(this.hiddenName && !Ext.isDefined(this.submitValue)){
  480. this.submitValue = false;
  481. }
  482. Ext.form.ComboBox.superclass.onRender.call(this, ct, position);
  483. if(this.hiddenName){
  484. this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName,
  485. id: (this.hiddenId || Ext.id())}, 'before', true);
  486. }
  487. if(Ext.isGecko){
  488. this.el.dom.setAttribute('autocomplete', 'off');
  489. }
  490. if(!this.lazyInit){
  491. this.initList();
  492. }else{
  493. this.on('focus', this.initList, this, {single: true});
  494. }
  495. },
  496. // private
  497. initValue : function(){
  498. Ext.form.ComboBox.superclass.initValue.call(this);
  499. if(this.hiddenField){
  500. this.hiddenField.value =
  501. Ext.value(Ext.isDefined(this.hiddenValue) ? this.hiddenValue : this.value, '');
  502. }
  503. },
  504. getParentZIndex : function(){
  505. var zindex;
  506. if (this.ownerCt){
  507. this.findParentBy(function(ct){
  508. zindex = parseInt(ct.getPositionEl().getStyle('z-index'), 10);
  509. return !!zindex;
  510. });
  511. }
  512. return zindex;
  513. },
  514. getZIndex : function(listParent){
  515. listParent = listParent || Ext.getDom(this.getListParent() || Ext.getBody());
  516. var zindex = parseInt(Ext.fly(listParent).getStyle('z-index'), 10);
  517. if(!zindex){
  518. zindex = this.getParentZIndex();
  519. }
  520. return (zindex || 12000) + 5;
  521. },
  522. // private
  523. initList : function(){
  524. if(!this.list){
  525. var cls = 'x-combo-list',
  526. listParent = Ext.getDom(this.getListParent() || Ext.getBody());
  527. this.list = new Ext.Layer({
  528. parentEl: listParent,
  529. shadow: this.shadow,
  530. cls: [cls, this.listClass].join(' '),
  531. constrain:false,
  532. zindex: this.getZIndex(listParent)
  533. });
  534. var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
  535. this.list.setSize(lw, 0);
  536. this.list.swallowEvent('mousewheel');
  537. this.assetHeight = 0;
  538. if(this.syncFont !== false){
  539. this.list.setStyle('font-size', this.el.getStyle('font-size'));
  540. }
  541. if(this.title){
  542. this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
  543. this.assetHeight += this.header.getHeight();
  544. }
  545. this.innerList = this.list.createChild({cls:cls+'-inner'});
  546. this.mon(this.innerList, 'mouseover', this.onViewOver, this);
  547. this.mon(this.innerList, 'mousemove', this.onViewMove, this);
  548. this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
  549. if(this.pageSize){
  550. this.footer = this.list.createChild({cls:cls+'-ft'});
  551. this.pageTb = new Ext.PagingToolbar({
  552. store: this.store,
  553. pageSize: this.pageSize,
  554. renderTo:this.footer
  555. });
  556. this.assetHeight += this.footer.getHeight();
  557. }
  558. if(!this.tpl){
  559. <div id="cfg-Ext.form.ComboBox-tpl"></div>/**
  560. * @cfg {String/Ext.XTemplate} tpl <p>The template string, or {@link Ext.XTemplate} instance to
  561. * use to display each item in the dropdown list. The dropdown list is displayed in a
  562. * DataView. See {@link #view}.</p>
  563. * <p>The default template string is:</p><pre><code>
  564. '&lt;tpl for=".">&lt;div class="x-combo-list-item">{' + this.displayField + '}&lt;/div>&lt;/tpl>'
  565. * </code></pre>
  566. * <p>Override the default value to create custom UI layouts for items in the list.
  567. * For example:</p><pre><code>
  568. '&lt;tpl for=".">&lt;div ext:qtip="{state}. {nick}" class="x-combo-list-item">{state}&lt;/div>&lt;/tpl>'
  569. * </code></pre>
  570. * <p>The template <b>must</b> contain one or more substitution parameters using field
  571. * names from the Combo's</b> {@link #store Store}. In the example above an
  572. * <pre>ext:qtip</pre> attribute is added to display other fields from the Store.</p>
  573. * <p>To preserve the default visual look of list items, add the CSS class name
  574. * <pre>x-combo-list-item</pre> to the template's container element.</p>
  575. * <p>Also see {@link #itemSelector} for additional details.</p>
  576. */
  577. this.tpl = '<tpl for="."><div class="'+cls+'-item">{' + this.displayField + '}</div></tpl>';
  578. <div id="cfg-Ext.form.ComboBox-itemSelector"></div>/**
  579. * @cfg {String} itemSelector
  580. * <p>A simple CSS selector (e.g. div.some-class or span:first-child) that will be
  581. * used to determine what nodes the {@link #view Ext.DataView} which handles the dropdown
  582. * display will be working with.</p>
  583. * <p><b>Note</b>: this setting is <b>required</b> if a custom XTemplate has been
  584. * specified in {@link #tpl} which assigns a class other than <pre>'x-combo-list-item'</pre>
  585. * to dropdown list items</b>
  586. */
  587. }
  588. <div id="prop-Ext.form.ComboBox-view"></div>/**
  589. * The {@link Ext.DataView DataView} used to display the ComboBox's options.
  590. * @type Ext.DataView
  591. */
  592. this.view = new Ext.DataView({
  593. applyTo: this.innerList,
  594. tpl: this.tpl,
  595. singleSelect: true,
  596. selectedClass: this.selectedClass,
  597. itemSelector: this.itemSelector || '.' + cls + '-item',
  598. emptyText: this.listEmptyText,
  599. deferEmptyText: false
  600. });
  601. this.mon(this.view, {
  602. containerclick : this.onViewClick,
  603. click : this.onViewClick,
  604. scope :this
  605. });
  606. this.bindStore(this.store, true);
  607. if(this.resizable){
  608. this.resizer = new Ext.Resizable(this.list, {
  609. pinned:true, handles:'se'
  610. });
  611. this.mon(this.resizer, 'resize', function(r, w, h){
  612. this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
  613. this.listWidth = w;
  614. this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
  615. this.restrictHeight();
  616. }, this);
  617. this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
  618. }
  619. }
  620. },
  621. <div id="method-Ext.form.ComboBox-getListParent"></div>/**
  622. * <p>Returns the element used to house this ComboBox's pop-up list. Defaults to the document body.</p>
  623. * A custom implementation may be provided as a configuration option if the floating list needs to be rendered
  624. * to a different Element. An example might be rendering the list inside a Menu so that clicking
  625. * the list does not hide the Menu:<pre><code>
  626. var store = new Ext.data.ArrayStore({
  627. autoDestroy: true,
  628. fields: ['initials', 'fullname'],
  629. data : [
  630. ['FF', 'Fred Flintstone'],
  631. ['BR', 'Barney Rubble']
  632. ]
  633. });
  634. var combo = new Ext.form.ComboBox({
  635. store: store,
  636. displayField: 'fullname',
  637. emptyText: 'Select a name...',
  638. forceSelection: true,
  639. getListParent: function() {
  640. return this.el.up('.x-menu');
  641. },
  642. iconCls: 'no-icon', //use iconCls if placing within menu to shift to right side of menu
  643. mode: 'local',
  644. selectOnFocus: true,
  645. triggerAction: 'all',
  646. typeAhead: true,
  647. width: 135
  648. });
  649. var menu = new Ext.menu.Menu({
  650. id: 'mainMenu',
  651. items: [
  652. combo // A Field in a Menu
  653. ]
  654. });
  655. </code></pre>
  656. */
  657. getListParent : function() {
  658. return document.body;
  659. },
  660. <div id="method-Ext.form.ComboBox-getStore"></div>/**
  661. * Returns the store associated with this combo.
  662. * @return {Ext.data.Store} The store
  663. */
  664. getStore : function(){
  665. return this.store;
  666. },
  667. // private
  668. bindStore : function(store, initial){
  669. if(this.store && !initial){
  670. if(this.store !== store && this.store.autoDestroy){
  671. this.store.destroy();
  672. }else{
  673. this.store.un('beforeload', this.onBeforeLoad, this);
  674. this.store.un('load', this.onLoad, this);
  675. this.store.un('exception', this.collapse, this);
  676. }
  677. if(!store){
  678. this.store = null;
  679. if(this.view){
  680. this.view.bindStore(null);
  681. }
  682. if(this.pageTb){
  683. this.pageTb.bindStore(null);
  684. }
  685. }
  686. }
  687. if(store){
  688. if(!initial) {
  689. this.lastQuery = null;
  690. if(this.pageTb) {
  691. this.pageTb.bindStore(store);
  692. }
  693. }
  694. this.store = Ext.StoreMgr.lookup(store);
  695. this.store.on({
  696. scope: this,
  697. beforeload: this.onBeforeLoad,
  698. load: this.onLoad,
  699. exception: this.collapse
  700. });
  701. if(this.view){
  702. this.view.bindStore(store);
  703. }
  704. }
  705. },
  706. reset : function(){
  707. if(this.clearFilterOnReset && this.mode == 'local'){
  708. this.store.clearFilter();
  709. }
  710. Ext.form.ComboBox.superclass.reset.call(this);
  711. },
  712. // private
  713. initEvents : function(){
  714. Ext.form.ComboBox.superclass.initEvents.call(this);
  715. <div id="prop-Ext.form.ComboBox-keyNav"></div>/**
  716. * @property keyNav
  717. * @type Ext.KeyNav
  718. * <p>A {@link Ext.KeyNav KeyNav} object which handles navigation keys for this ComboBox. This performs actions
  719. * based on keystrokes typed when the input field is focused.</p>
  720. * <p><b>After the ComboBox has been rendered</b>, you may override existing navigation key functionality,
  721. * or add your own based upon key names as specified in the {@link Ext.KeyNav KeyNav} class.</p>
  722. * <p>The function is executed in the scope (<code>this</code> reference of the ComboBox. Example:</p><pre><code>
  723. myCombo.keyNav.esc = function(e) { // Override ESC handling function
  724. this.collapse(); // Standard behaviour of Ext's ComboBox.
  725. this.setValue(this.startValue); // We reset to starting value on ESC
  726. };
  727. myCombo.keyNav.tab = function() { // Override TAB handling function
  728. this.onViewClick(false); // Select the currently highlighted row
  729. };
  730. </code></pre>
  731. */
  732. this.keyNav = new Ext.KeyNav(this.el, {
  733. "up" : function(e){
  734. this.inKeyMode = true;
  735. this.selectPrev();
  736. },
  737. "down" : function(e){
  738. if(!this.isExpanded()){
  739. this.onTriggerClick();
  740. }else{
  741. this.inKeyMode = true;
  742. this.selectNext();
  743. }
  744. },
  745. "enter" : function(e){
  746. this.onViewClick();
  747. },
  748. "esc" : function(e){
  749. this.collapse();
  750. },
  751. "tab" : function(e){
  752. if (this.forceSelection === true) {
  753. this.collapse();
  754. } else {
  755. this.onViewClick(false);
  756. }
  757. return true;
  758. },
  759. scope : this,
  760. doRelay : function(e, h, hname){
  761. if(hname == 'down' || this.scope.isExpanded()){
  762. // this MUST be called before ComboBox#fireKey()
  763. var relay = Ext.KeyNav.prototype.doRelay.apply(this, arguments);
  764. if(!Ext.isIE && Ext.EventManager.useKeydown){
  765. // call Combo#fireKey() for browsers which use keydown event (except IE)
  766. this.scope.fireKey(e);
  767. }
  768. return relay;
  769. }
  770. return true;
  771. },
  772. forceKeyDown : true,
  773. defaultEventAction: 'stopEvent'
  774. });
  775. this.queryDelay = Math.max(this.queryDelay || 10,
  776. this.mode == 'local' ? 10 : 250);
  777. this.dqTask = new Ext.util.DelayedTask(this.initQuery, this);
  778. if(this.typeAhead){
  779. this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this);
  780. }
  781. if(!this.enableKeyEvents){
  782. this.mon(this.el, 'keyup', this.onKeyUp, this);
  783. }
  784. },
  785. // private
  786. onDestroy : function(){
  787. if (this.dqTask){
  788. this.dqTask.cancel();
  789. this.dqTask = null;
  790. }
  791. this.bindStore(null);
  792. Ext.destroy(
  793. this.resizer,
  794. this.view,
  795. this.pageTb,
  796. this.list
  797. );
  798. Ext.destroyMembers(this, 'hiddenField');
  799. Ext.form.ComboBox.superclass.onDestroy.call(this);
  800. },
  801. // private
  802. fireKey : function(e){
  803. if (!this.isExpanded()) {
  804. Ext.form.ComboBox.superclass.fireKey.call(this, e);
  805. }
  806. },
  807. // private
  808. onResize : function(w, h){
  809. Ext.form.ComboBox.superclass.onResize.apply(this, arguments);
  810. if(!isNaN(w) && this.isVisible() && this.list){
  811. this.doResize(w);
  812. }else{
  813. this.bufferSize = w;
  814. }
  815. },
  816. doResize: function(w){
  817. if(!Ext.isDefined(this.listWidth)){
  818. var lw = Math.max(w, this.minListWidth);
  819. this.list.setWidth(lw);
  820. this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
  821. }
  822. },
  823. // private
  824. onEnable : function(){
  825. Ext.form.ComboBox.superclass.onEnable.apply(this, arguments);
  826. if(this.hiddenField){
  827. this.hiddenField.disabled = false;
  828. }
  829. },
  830. // private
  831. onDisable : function(){
  832. Ext.form.ComboBox.superclass.onDisable.apply(this, arguments);
  833. if(this.hiddenField){
  834. this.hiddenField.disabled = true;
  835. }
  836. },
  837. // private
  838. onBeforeLoad : function(){
  839. if(!this.hasFocus){
  840. return;
  841. }
  842. this.innerList.update(this.loadingText ?
  843. '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
  844. this.restrictHeight();
  845. this.selectedIndex = -1;
  846. },
  847. // private
  848. onLoad : function(){
  849. if(!this.hasFocus){
  850. return;
  851. }
  852. if(this.store.getCount() > 0 || this.listEmptyText){
  853. this.expand();
  854. this.restrictHeight();
  855. if(this.lastQuery == this.allQuery){
  856. if(this.editable){
  857. this.el.dom.select();
  858. }
  859. if(this.autoSelect !== false && !this.selectByValue(this.value, true)){
  860. this.select(0, true);
  861. }
  862. }else{
  863. if(this.autoSelect !== false){
  864. this.selectNext();
  865. }
  866. if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
  867. this.taTask.delay(this.typeAheadDelay);
  868. }
  869. }
  870. }else{
  871. this.collapse();
  872. }
  873. },
  874. // private
  875. onTypeAhead : function(){
  876. if(this.store.getCount() > 0){
  877. var r = this.store.getAt(0);
  878. var newValue = r.data[this.displayField];
  879. var len = newValue.length;
  880. var selStart = this.getRawValue().length;
  881. if(selStart != len){
  882. this.setRawValue(newValue);
  883. this.selectText(selStart, newValue.length);
  884. }
  885. }
  886. },
  887. // private
  888. assertValue : function(){
  889. var val = this.getRawValue(),
  890. rec;
  891. if(this.valueField && Ext.isDefined(this.value)){
  892. rec = this.findRecord(this.valueField, this.value);
  893. }
  894. if(!rec || rec.get(this.displayField) != val){
  895. rec = this.findRecord(this.displayField, val);
  896. }
  897. if(!rec && this.forceSelection){
  898. if(val.length > 0 && val != this.emptyText){
  899. this.el.dom.value = Ext.value(this.lastSelectionText, '');
  900. this.applyEmptyText();
  901. }else{
  902. this.clearValue();
  903. }
  904. }else{
  905. if(rec && this.valueField){
  906. // onSelect may have already set the value and by doing so
  907. // set the display field properly. Let's not wipe out the
  908. // valueField here by just sending the displayField.
  909. if (this.value == val){
  910. return;
  911. }
  912. val = rec.get(this.valueField || this.displayField);
  913. }
  914. this.setValue(val);
  915. }
  916. },
  917. // private
  918. onSelect : function(record, index){
  919. if(this.fireEvent('beforeselect', this, record, index) !== false){
  920. this.setValue(record.data[this.valueField || this.displayField]);
  921. this.collapse();
  922. this.fireEvent('select', this, record, index);
  923. }
  924. },
  925. // inherit docs
  926. getName: function(){
  927. var hf = this.hiddenField;
  928. return hf && hf.name ? hf.name : this.hiddenName || Ext.form.ComboBox.superclass.getName.call(this);
  929. },
  930. <div id="method-Ext.form.ComboBox-getValue"></div>/**
  931. * Returns the currently selected field value or empty string if no value is set.
  932. * @return {String} value The selected value
  933. */
  934. getValue : function(){
  935. if(this.valueField){
  936. return Ext.isDefined(this.value) ? this.value : '';
  937. }else{
  938. return Ext.form.ComboBox.superclass.getValue.call(this);
  939. }
  940. },
  941. <div id="method-Ext.form.ComboBox-clearValue"></div>/**
  942. * Clears any text/value currently set in the field
  943. */
  944. clearValue : function(){
  945. if(this.hiddenField){
  946. this.hiddenField.value = '';
  947. }
  948. this.setRawValue('');
  949. this.lastSelectionText = '';
  950. this.applyEmptyText();
  951. this.value = '';
  952. },
  953. <div id="method-Ext.form.ComboBox-setValue"></div>/**
  954. * Sets the specified value into the field. If the value finds a match, the corresponding record text
  955. * will be displayed in the field. If the value does not match the data value of an existing item,
  956. * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
  957. * Otherwise the field will be blank (although the value will still be set).
  958. * @param {String} value The value to match
  959. * @return {Ext.form.Field} this
  960. */
  961. setValue : function(v){
  962. var text = v;
  963. if(this.valueField){
  964. var r = this.findRecord(this.valueField, v);
  965. if(r){
  966. text = r.data[this.displayField];
  967. }else if(Ext.isDefined(this.valueNotFoundText)){
  968. text = this.valueNotFoundText;
  969. }
  970. }
  971. this.lastSelectionText = text;
  972. if(this.hiddenField){
  973. this.hiddenField.value = Ext.value(v, '');
  974. }
  975. Ext.form.ComboBox.superclass.setValue.call(this, text);
  976. this.value = v;
  977. return this;
  978. },
  979. // private
  980. findRecord : function(prop, value){
  981. var record;
  982. if(this.store.getCount() > 0){
  983. this.store.each(function(r){
  984. if(r.data[prop] == value){
  985. record = r;
  986. return false;
  987. }
  988. });
  989. }
  990. return record;
  991. },
  992. // private
  993. onViewMove : function(e, t){
  994. this.inKeyMode = false;
  995. },
  996. // private
  997. onViewOver : function(e, t){
  998. if(this.inKeyMode){ // prevent key nav and mouse over conflicts
  999. return;
  1000. }
  1001. var item = this.view.findItemFromChild(t);
  1002. if(item){
  1003. var index = this.view.indexOf(item);
  1004. this.select(index, false);
  1005. }
  1006. },
  1007. // private
  1008. onViewClick : function(doFocus){
  1009. var index = this.view.getSelectedIndexes()[0],
  1010. s = this.store,
  1011. r = s.getAt(index);
  1012. if(r){
  1013. this.onSelect(r, index);
  1014. }else {
  1015. this.collapse();
  1016. }
  1017. if(doFocus !== false){
  1018. this.el.focus();
  1019. }
  1020. },
  1021. // private
  1022. restrictHeight : function(){
  1023. this.innerList.dom.style.height = '';
  1024. var inner = this.innerList.dom,
  1025. pad = this.list.getFrameWidth('tb') + (this.resizable ? this.handleHeight : 0) + this.assetHeight,
  1026. h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight),
  1027. ha = this.getPosition()[1]-Ext.getBody().getScroll().top,
  1028. hb = Ext.lib.Dom.getViewHeight()-ha-this.getSize().height,
  1029. space = Math.max(ha, hb, this.minHeight || 0)-this.list.shadowOffset-pad-5;
  1030. h = Math.min(h, space, this.maxHeight);
  1031. this.innerList.setHeight(h);
  1032. this.list.beginUpdate();
  1033. this.list.setHeight(h+pad);
  1034. this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
  1035. this.list.endUpdate();
  1036. },
  1037. <div id="method-Ext.form.ComboBox-isExpanded"></div>/**
  1038. * Returns true if the dropdown list is expanded, else false.
  1039. */
  1040. isExpanded : function(){
  1041. return this.list && this.list.isVisible();
  1042. },
  1043. <div id="method-Ext.form.ComboBox-selectByValue"></div>/**
  1044. * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
  1045. * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
  1046. * @param {String} value The data value of the item to select
  1047. * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
  1048. * selected item if it is not currently in view (defaults to true)
  1049. * @return {Boolean} True if the value matched an item in the list, else false
  1050. */
  1051. selectByValue : function(v, scrollIntoView){
  1052. if(!Ext.isEmpty(v, true)){
  1053. var r = this.findRecord(this.valueField || this.displayField, v);
  1054. if(r){
  1055. this.select(this.store.indexOf(r), scrollIntoView);
  1056. return true;
  1057. }
  1058. }
  1059. return false;
  1060. },
  1061. <div id="method-Ext.form.ComboBox-select"></div>/**
  1062. * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
  1063. * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
  1064. * @param {Number} index The zero-based index of the list item to select
  1065. * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
  1066. * selected item if it is not currently in view (defaults to true)
  1067. */
  1068. select : function(index, scrollIntoView){
  1069. this.selectedIndex = index;
  1070. this.view.select(index);
  1071. if(scrollIntoView !== false){
  1072. var el = this.view.getNode(index);
  1073. if(el){
  1074. this.innerList.scrollChildIntoView(el, false);
  1075. }
  1076. }
  1077. },
  1078. // private
  1079. selectNext : function(){
  1080. var ct = this.store.getCount();
  1081. if(ct > 0){
  1082. if(this.selectedIndex == -1){
  1083. this.select(0);
  1084. }else if(this.selectedIndex < ct-1){
  1085. this.select(this.selectedIndex+1);
  1086. }
  1087. }
  1088. },
  1089. // private
  1090. selectPrev : function(){
  1091. var ct = this.store.getCount();
  1092. if(ct > 0){
  1093. if(this.selectedIndex == -1){
  1094. this.select(0);
  1095. }else if(this.selectedIndex !== 0){
  1096. this.select(this.selectedIndex-1);
  1097. }
  1098. }
  1099. },
  1100. // private
  1101. onKeyUp : function(e){
  1102. var k = e.getKey();
  1103. if(this.editable !== false && this.readOnly !== true && (k == e.BACKSPACE || !e.isSpecialKey())){
  1104. this.lastKey = k;
  1105. this.dqTask.delay(this.queryDelay);
  1106. }
  1107. Ext.form.ComboBox.superclass.onKeyUp.call(this, e);
  1108. },
  1109. // private
  1110. validateBlur : function(){
  1111. return !this.list || !this.list.isVisible();
  1112. },
  1113. // private
  1114. initQuery : function(){
  1115. this.doQuery(this.getRawValue());
  1116. },
  1117. // private
  1118. beforeBlur : function(){
  1119. this.assertValue();
  1120. },
  1121. // private
  1122. postBlur : function(){
  1123. Ext.form.ComboBox.superclass.postBlur.call(this);
  1124. this.collapse();
  1125. this.inKeyMode = false;
  1126. },
  1127. <div id="method-Ext.form.ComboBox-doQuery"></div>/**
  1128. * Execute a query to filter the dropdown list. Fires the {@link #beforequery} event prior to performing the
  1129. * query allowing the query action to be canceled if needed.
  1130. * @param {String} query The SQL query to execute
  1131. * @param {Boolean} forceAll <tt>true</tt> to force the query to execute even if there are currently fewer
  1132. * characters in the field than the minimum specified by the <tt>{@link #minChars}</tt> config option. It
  1133. * also clears any filter previously saved in the current store (defaults to <tt>false</tt>)
  1134. */
  1135. doQuery : function(q, forceAll){
  1136. q = Ext.isEmpty(q) ? '' : q;
  1137. var qe = {
  1138. query: q,
  1139. forceAll: forceAll,
  1140. combo: this,
  1141. cancel:false
  1142. };
  1143. if(this.fireEvent('beforequery', qe)===false || qe.cancel){
  1144. return false;
  1145. }
  1146. q = qe.query;
  1147. forceAll = qe.forceAll;
  1148. if(forceAll === true || (q.length >= this.minChars)){
  1149. if(this.lastQuery !== q){
  1150. this.lastQuery = q;
  1151. if(this.mode == 'local'){
  1152. this.selectedIndex = -1;
  1153. if(forceAll){
  1154. this.store.clearFilter();
  1155. }else{
  1156. this.store.filter(this.displayField, q);
  1157. }
  1158. this.onLoad();
  1159. }else{
  1160. this.store.baseParams[this.queryParam] = q;
  1161. this.store.load({
  1162. params: this.getParams(q)
  1163. });
  1164. this.expand();
  1165. }
  1166. }else{
  1167. this.selectedIndex = -1;
  1168. this.onLoad();
  1169. }
  1170. }
  1171. },
  1172. // private
  1173. getParams : function(q){
  1174. var params = {},
  1175. paramNames = this.store.paramNames;
  1176. if(this.pageSize){
  1177. params[paramNames.start] = 0;
  1178. params[paramNames.limit] = this.pageSize;
  1179. }
  1180. return params;
  1181. },
  1182. <div id="method-Ext.form.ComboBox-collapse"></div>/**
  1183. * Hides the dropdown list if it is currently expanded. Fires the {@link #collapse} event on completion.
  1184. */
  1185. collapse : function(){
  1186. if(!this.isExpanded()){
  1187. return;
  1188. }
  1189. this.list.hide();
  1190. Ext.getDoc().un('mousewheel', this.collapseIf, this);
  1191. Ext.getDoc().un('mousedown', this.collapseIf, this);
  1192. this.fireEvent('collapse', this);
  1193. },
  1194. // private
  1195. collapseIf : function(e){
  1196. if(!this.isDestroyed && !e.within(this.wrap) && !e.within(this.list)){
  1197. this.collapse();
  1198. }
  1199. },
  1200. <div id="method-Ext.form.ComboBox-expand"></div>/**
  1201. * Expands the dropdown list if it is currently hidden. Fires the {@link #expand} event on completion.
  1202. */
  1203. expand : function(){
  1204. if(this.isExpanded() || !this.hasFocus){
  1205. return;
  1206. }
  1207. if(this.title || this.pageSize){
  1208. this.assetHeight = 0;
  1209. if(this.title){
  1210. this.assetHeight += this.header.getHeight();
  1211. }
  1212. if(this.pageSize){
  1213. this.assetHeight += this.footer.getHeight();
  1214. }
  1215. }
  1216. if(this.bufferSize){
  1217. this.doResize(this.bufferSize);
  1218. delete this.bufferSize;
  1219. }
  1220. this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign));
  1221. // zindex can change, re-check it and set it if necessary
  1222. this.list.setZIndex(this.getZIndex());
  1223. this.list.show();
  1224. if(Ext.isGecko2){
  1225. this.innerList.setOverflow('auto'); // necessary for FF 2.0/Mac
  1226. }
  1227. this.mon(Ext.getDoc(), {
  1228. scope: this,
  1229. mousewheel: this.collapseIf,
  1230. mousedown: this.collapseIf
  1231. });
  1232. this.fireEvent('expand', this);
  1233. },
  1234. <div id="method-Ext.form.ComboBox-onTriggerClick"></div>/**
  1235. * @method onTriggerClick
  1236. * @hide
  1237. */
  1238. // private
  1239. // Implements the default empty TriggerField.onTriggerClick function
  1240. onTriggerClick : function(){
  1241. if(this.readOnly || this.disabled){
  1242. return;
  1243. }
  1244. if(this.isExpanded()){
  1245. this.collapse();
  1246. this.el.focus();
  1247. }else {
  1248. this.onFocus({});
  1249. if(this.triggerAction == 'all') {
  1250. this.doQuery(this.allQuery, true);
  1251. } else {
  1252. this.doQuery(this.getRawValue());
  1253. }
  1254. this.el.focus();
  1255. }
  1256. }
  1257. <div id="method-Ext.form.ComboBox-autoSize"></div>/**
  1258. * @hide
  1259. * @method autoSize
  1260. */
  1261. <div id="cfg-Ext.form.ComboBox-grow"></div>/**
  1262. * @cfg {Boolean} grow @hide
  1263. */
  1264. <div id="cfg-Ext.form.ComboBox-growMin"></div>/**
  1265. * @cfg {Number} growMin @hide
  1266. */
  1267. <div id="cfg-Ext.form.ComboBox-growMax"></div>/**
  1268. * @cfg {Number} growMax @hide
  1269. */
  1270. });
  1271. Ext.reg('combo', Ext.form.ComboBox);
  1272. </pre>
  1273. </body>
  1274. </html>