4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-form-field-Picker'>/**
19 </span> * @class Ext.form.field.Picker
20 * @extends Ext.form.field.Trigger
21 * <p>An abstract class for fields that have a single trigger which opens a "picker" popup below
22 * the field, e.g. a combobox menu list or a date picker. It provides a base implementation for
23 * toggling the picker's visibility when the trigger is clicked, as well as keyboard navigation
24 * and some basic events. Sizing and alignment of the picker can be controlled via the {@link #matchFieldWidth}
25 * and {@link #pickerAlign}/{@link #pickerOffset} config properties respectively.</p>
26 * <p>You would not normally use this class directly, but instead use it as the parent class for
27 * a specific picker field implementation. Subclasses must implement the {@link #createPicker} method
28 * to create a picker component appropriate for the field.</p>
31 Ext.define('Ext.form.field.Picker', {
32 extend: 'Ext.form.field.Trigger',
33 alias: 'widget.pickerfield',
34 alternateClassName: 'Ext.form.Picker',
35 requires: ['Ext.util.KeyNav'],
37 <span id='Ext-form-field-Picker-cfg-matchFieldWidth'> /**
38 </span> * @cfg {Boolean} matchFieldWidth
39 * Whether the picker dropdown's width should be explicitly set to match the width of the field.
40 * Defaults to <tt>true</tt>.
42 matchFieldWidth: true,
44 <span id='Ext-form-field-Picker-cfg-pickerAlign'> /**
45 </span> * @cfg {String} pickerAlign
46 * The {@link Ext.core.Element#alignTo alignment position} with which to align the picker. Defaults
47 * to <tt>"tl-bl?"</tt>
49 pickerAlign: 'tl-bl?',
51 <span id='Ext-form-field-Picker-cfg-pickerOffset'> /**
52 </span> * @cfg {Array} pickerOffset
53 * An offset [x,y] to use in addition to the {@link #pickerAlign} when positioning the picker.
54 * Defaults to undefined.
57 <span id='Ext-form-field-Picker-cfg-openCls'> /**
58 </span> * @cfg {String} openCls
59 * A class to be added to the field's {@link #bodyEl} element when the picker is opened. Defaults
60 * to 'x-pickerfield-open'.
62 openCls: Ext.baseCSSPrefix + 'pickerfield-open',
64 <span id='Ext-form-field-Picker-property-isExpanded'> /**
65 </span> * @property isExpanded
67 * True if the picker is currently expanded, false if not.
70 <span id='Ext-form-field-Picker-cfg-editable'> /**
71 </span> * @cfg {Boolean} editable <tt>false</tt> to prevent the user from typing text directly into the field;
72 * the field can only have its value set via selecting a value from the picker. In this state, the picker
73 * can also be opened by clicking directly on the input field itself.
74 * (defaults to <tt>true</tt>).
79 initComponent: function() {
84 <span id='Ext-form-field-Picker-event-expand'> /**
85 </span> * @event expand
86 * Fires when the field's picker is expanded.
87 * @param {Ext.form.field.Picker} field This field instance
90 <span id='Ext-form-field-Picker-event-collapse'> /**
91 </span> * @event collapse
92 * Fires when the field's picker is collapsed.
93 * @param {Ext.form.field.Picker} field This field instance
96 <span id='Ext-form-field-Picker-event-select'> /**
97 </span> * @event select
98 * Fires when a value is selected via the picker.
99 * @param {Ext.form.field.Picker} field This field instance
100 * @param {Mixed} value The value that was selected. The exact type of this value is dependent on
101 * the individual field and picker implementations.
108 initEvents: function() {
112 // Add handlers for keys to expand/collapse the picker
113 me.keyNav = Ext.create('Ext.util.KeyNav', me.inputEl, {
115 if (!me.isExpanded) {
116 // Don't call expand() directly as there may be additional processing involved before
117 // expanding, e.g. in the case of a ComboBox query.
126 // Non-editable allows opening the picker by clicking the field
128 me.mon(me.inputEl, 'click', me.onTriggerClick, me);
131 // Disable native browser autocomplete
133 me.inputEl.dom.setAttribute('autocomplete', 'off');
138 <span id='Ext-form-field-Picker-method-expand'> /**
139 </span> * Expand this field's picker dropdown.
143 bodyEl, picker, collapseIf;
145 if (me.rendered && !me.isExpanded && !me.isDestroyed) {
147 picker = me.getPicker();
148 collapseIf = me.collapseIf;
150 // show the picker and set isExpanded flag
152 me.isExpanded = true;
154 bodyEl.addCls(me.openCls);
156 // monitor clicking and mousewheel
157 me.mon(Ext.getDoc(), {
158 mousewheel: collapseIf,
159 mousedown: collapseIf,
162 Ext.EventManager.onWindowResize(me.alignPicker, me);
163 me.fireEvent('expand', me);
168 onExpand: Ext.emptyFn,
170 <span id='Ext-form-field-Picker-method-alignPicker'> /**
172 * Aligns the picker to the
174 alignPicker: function() {
179 if (this.isExpanded) {
180 picker = me.getPicker();
181 if (me.matchFieldWidth) {
182 // Auto the height (it will be constrained by min and max width) unless there are no records to display.
183 picker.setSize(me.bodyEl.getWidth(), picker.store && picker.store.getCount() ? null : 0);
185 if (picker.isFloating()) {
186 picker.alignTo(me.inputEl, me.pickerAlign, me.pickerOffset);
188 // add the {openCls}-above class if the picker was aligned above
189 // the field due to hitting the bottom of the viewport
190 isAbove = picker.el.getY() < me.inputEl.getY();
191 me.bodyEl[isAbove ? 'addCls' : 'removeCls'](me.openCls + aboveSfx);
192 picker.el[isAbove ? 'addCls' : 'removeCls'](picker.baseCls + aboveSfx);
197 <span id='Ext-form-field-Picker-method-collapse'> /**
198 </span> * Collapse this field's picker dropdown.
200 collapse: function() {
201 if (this.isExpanded && !this.isDestroyed) {
203 openCls = me.openCls,
206 collapseIf = me.collapseIf,
209 // hide the picker and set isExpanded flag
211 me.isExpanded = false;
213 // remove the openCls
214 me.bodyEl.removeCls([openCls, openCls + aboveSfx]);
215 picker.el.removeCls(picker.baseCls + aboveSfx);
217 // remove event listeners
218 doc.un('mousewheel', collapseIf, me);
219 doc.un('mousedown', collapseIf, me);
220 Ext.EventManager.removeResizeListener(me.alignPicker, me);
221 me.fireEvent('collapse', me);
226 onCollapse: Ext.emptyFn,
229 <span id='Ext-form-field-Picker-method-collapseIf'> /**
231 * Runs on mousewheel and mousedown of doc to check to see if we should collapse the picker
233 collapseIf: function(e) {
235 if (!me.isDestroyed && !e.within(me.bodyEl, false, true) && !e.within(me.picker.el, false, true)) {
240 <span id='Ext-form-field-Picker-method-getPicker'> /**
241 </span> * Return a reference to the picker component for this field, creating it if necessary by
242 * calling {@link #createPicker}.
243 * @return {Ext.Component} The picker component
245 getPicker: function() {
247 return me.picker || (me.picker = me.createPicker());
250 <span id='Ext-form-field-Picker-property-createPicker'> /**
251 </span> * Create and return the component to be used as this field's picker. Must be implemented
252 * by subclasses of Picker.
253 * @return {Ext.Component} The picker component
255 createPicker: Ext.emptyFn,
257 <span id='Ext-form-field-Picker-method-onTriggerClick'> /**
258 </span> * Handles the trigger click; by default toggles between expanding and collapsing the
261 onTriggerClick: function() {
263 if (!me.readOnly && !me.disabled) {
273 mimicBlur: function(e) {
276 // ignore mousedown events within the picker element
277 if (!picker || !e.within(picker.el, false, true)) {
278 me.callParent(arguments);
282 onDestroy : function(){
284 Ext.EventManager.removeResizeListener(me.alignPicker, me);
285 Ext.destroy(me.picker, me.keyNav);