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-method-constructor'><span id='Ext-form-field-Picker'>/**
19 </span></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>
32 * Create a new picker field
33 * @param {Object} config
35 Ext.define('Ext.form.field.Picker', {
36 extend: 'Ext.form.field.Trigger',
37 alias: 'widget.pickerfield',
38 alternateClassName: 'Ext.form.Picker',
39 requires: ['Ext.util.KeyNav'],
41 <span id='Ext-form-field-Picker-cfg-matchFieldWidth'> /**
42 </span> * @cfg {Boolean} matchFieldWidth
43 * Whether the picker dropdown's width should be explicitly set to match the width of the field.
44 * Defaults to <tt>true</tt>.
46 matchFieldWidth: true,
48 <span id='Ext-form-field-Picker-cfg-pickerAlign'> /**
49 </span> * @cfg {String} pickerAlign
50 * The {@link Ext.core.Element#alignTo alignment position} with which to align the picker. Defaults
51 * to <tt>"tl-bl?"</tt>
53 pickerAlign: 'tl-bl?',
55 <span id='Ext-form-field-Picker-cfg-pickerOffset'> /**
56 </span> * @cfg {Array} pickerOffset
57 * An offset [x,y] to use in addition to the {@link #pickerAlign} when positioning the picker.
58 * Defaults to undefined.
61 <span id='Ext-form-field-Picker-cfg-openCls'> /**
62 </span> * @cfg {String} openCls
63 * A class to be added to the field's {@link #bodyEl} element when the picker is opened. Defaults
64 * to 'x-pickerfield-open'.
66 openCls: Ext.baseCSSPrefix + 'pickerfield-open',
68 <span id='Ext-form-field-Picker-property-isExpanded'> /**
69 </span> * @property isExpanded
71 * True if the picker is currently expanded, false if not.
74 <span id='Ext-form-field-Picker-cfg-editable'> /**
75 </span> * @cfg {Boolean} editable <tt>false</tt> to prevent the user from typing text directly into the field;
76 * the field can only have its value set via selecting a value from the picker. In this state, the picker
77 * can also be opened by clicking directly on the input field itself.
78 * (defaults to <tt>true</tt>).
83 initComponent: function() {
88 <span id='Ext-form-field-Picker-event-expand'> /**
89 </span> * @event expand
90 * Fires when the field's picker is expanded.
91 * @param {Ext.form.field.Picker} field This field instance
94 <span id='Ext-form-field-Picker-event-collapse'> /**
95 </span> * @event collapse
96 * Fires when the field's picker is collapsed.
97 * @param {Ext.form.field.Picker} field This field instance
100 <span id='Ext-form-field-Picker-event-select'> /**
101 </span> * @event select
102 * Fires when a value is selected via the picker.
103 * @param {Ext.form.field.Picker} field This field instance
104 * @param {Mixed} value The value that was selected. The exact type of this value is dependent on
105 * the individual field and picker implementations.
112 initEvents: function() {
116 // Add handlers for keys to expand/collapse the picker
117 me.keyNav = Ext.create('Ext.util.KeyNav', me.inputEl, {
119 if (!me.isExpanded) {
120 // Don't call expand() directly as there may be additional processing involved before
121 // expanding, e.g. in the case of a ComboBox query.
130 // Non-editable allows opening the picker by clicking the field
132 me.mon(me.inputEl, 'click', me.onTriggerClick, me);
135 // Disable native browser autocomplete
137 me.inputEl.dom.setAttribute('autocomplete', 'off');
142 <span id='Ext-form-field-Picker-method-expand'> /**
143 </span> * Expand this field's picker dropdown.
147 bodyEl, picker, collapseIf;
149 if (me.rendered && !me.isExpanded && !me.isDestroyed) {
151 picker = me.getPicker();
152 collapseIf = me.collapseIf;
154 // show the picker and set isExpanded flag
156 me.isExpanded = true;
158 bodyEl.addCls(me.openCls);
160 // monitor clicking and mousewheel
161 me.mon(Ext.getDoc(), {
162 mousewheel: collapseIf,
163 mousedown: collapseIf,
166 Ext.EventManager.onWindowResize(me.alignPicker, me);
167 me.fireEvent('expand', me);
172 onExpand: Ext.emptyFn,
174 <span id='Ext-form-field-Picker-method-alignPicker'> /**
176 * Aligns the picker to the
178 alignPicker: function() {
183 if (this.isExpanded) {
184 picker = me.getPicker();
185 if (me.matchFieldWidth) {
186 // Auto the height (it will be constrained by min and max width) unless there are no records to display.
187 picker.setSize(me.bodyEl.getWidth(), picker.store && picker.store.getCount() ? null : 0);
189 if (picker.isFloating()) {
190 picker.alignTo(me.inputEl, me.pickerAlign, me.pickerOffset);
192 // add the {openCls}-above class if the picker was aligned above
193 // the field due to hitting the bottom of the viewport
194 isAbove = picker.el.getY() < me.inputEl.getY();
195 me.bodyEl[isAbove ? 'addCls' : 'removeCls'](me.openCls + aboveSfx);
196 picker.el[isAbove ? 'addCls' : 'removeCls'](picker.baseCls + aboveSfx);
201 <span id='Ext-form-field-Picker-method-collapse'> /**
202 </span> * Collapse this field's picker dropdown.
204 collapse: function() {
205 if (this.isExpanded && !this.isDestroyed) {
207 openCls = me.openCls,
210 collapseIf = me.collapseIf,
213 // hide the picker and set isExpanded flag
215 me.isExpanded = false;
217 // remove the openCls
218 me.bodyEl.removeCls([openCls, openCls + aboveSfx]);
219 picker.el.removeCls(picker.baseCls + aboveSfx);
221 // remove event listeners
222 doc.un('mousewheel', collapseIf, me);
223 doc.un('mousedown', collapseIf, me);
224 Ext.EventManager.removeResizeListener(me.alignPicker, me);
225 me.fireEvent('collapse', me);
230 onCollapse: Ext.emptyFn,
233 <span id='Ext-form-field-Picker-method-collapseIf'> /**
235 * Runs on mousewheel and mousedown of doc to check to see if we should collapse the picker
237 collapseIf: function(e) {
239 if (!me.isDestroyed && !e.within(me.bodyEl, false, true) && !e.within(me.picker.el, false, true)) {
244 <span id='Ext-form-field-Picker-method-getPicker'> /**
245 </span> * Return a reference to the picker component for this field, creating it if necessary by
246 * calling {@link #createPicker}.
247 * @return {Ext.Component} The picker component
249 getPicker: function() {
251 return me.picker || (me.picker = me.createPicker());
254 <span id='Ext-form-field-Picker-property-createPicker'> /**
255 </span> * Create and return the component to be used as this field's picker. Must be implemented
256 * by subclasses of Picker.
257 * @return {Ext.Component} The picker component
259 createPicker: Ext.emptyFn,
261 <span id='Ext-form-field-Picker-method-onTriggerClick'> /**
262 </span> * Handles the trigger click; by default toggles between expanding and collapsing the
265 onTriggerClick: function() {
267 if (!me.readOnly && !me.disabled) {
277 mimicBlur: function(e) {
280 // ignore mousedown events within the picker element
281 if (!picker || !e.within(picker.el, false, true)) {
282 me.callParent(arguments);
286 onDestroy : function(){
288 Ext.EventManager.removeResizeListener(me.alignPicker, me);
289 Ext.destroy(me.picker, me.keyNav);