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; }
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-Spinner'>/**
19 </span> * A field with a pair of up/down spinner buttons. This class is not normally instantiated directly,
20 * instead it is subclassed and the {@link #onSpinUp} and {@link #onSpinDown} methods are implemented
21 * to handle when the buttons are clicked. A good example of this is the {@link Ext.form.field.Number}
22 * field which uses the spinner to increment and decrement the field's value by its
23 * {@link Ext.form.field.Number#step step} config value.
28 * Ext.define('Ext.ux.CustomSpinner', {
29 * extend: 'Ext.form.field.Spinner',
30 * alias: 'widget.customspinner',
32 * // override onSpinUp (using step isn't neccessary)
33 * onSpinUp: function() {
36 * var val = me.step; // set the default value to the step value
37 * if(me.getValue() !== '') {
38 * val = parseInt(me.getValue().slice(0, -5)); // gets rid of " Pack"
40 * me.setValue((val + me.step) + ' Pack');
44 * // override onSpinDown
45 * onSpinDown: function() {
48 * if(me.getValue() !== '') {
49 * val = parseInt(me.getValue().slice(0, -5)); // gets rid of " Pack"
51 * me.setValue((val - me.step) + ' Pack');
56 * Ext.create('Ext.form.FormPanel', {
57 * title: 'Form with SpinnerField',
60 * renderTo: Ext.getBody(),
62 * xtype: 'customspinner',
63 * fieldLabel: 'How Much Beer?',
68 * By default, pressing the up and down arrow keys will also trigger the onSpinUp and onSpinDown methods;
69 * to prevent this, set `{@link #keyNavEnabled} = false`.
71 Ext.define('Ext.form.field.Spinner', {
72 extend: 'Ext.form.field.Trigger',
73 alias: 'widget.spinnerfield',
74 alternateClassName: 'Ext.form.Spinner',
75 requires: ['Ext.util.KeyNav'],
77 trigger1Cls: Ext.baseCSSPrefix + 'form-spinner-up',
78 trigger2Cls: Ext.baseCSSPrefix + 'form-spinner-down',
80 <span id='Ext-form-field-Spinner-cfg-spinUpEnabled'> /**
81 </span> * @cfg {Boolean} spinUpEnabled
82 * Specifies whether the up spinner button is enabled. Defaults to true. To change this after the component is
83 * created, use the {@link #setSpinUpEnabled} method.
87 <span id='Ext-form-field-Spinner-cfg-spinDownEnabled'> /**
88 </span> * @cfg {Boolean} spinDownEnabled
89 * Specifies whether the down spinner button is enabled. Defaults to true. To change this after the component is
90 * created, use the {@link #setSpinDownEnabled} method.
92 spinDownEnabled: true,
94 <span id='Ext-form-field-Spinner-cfg-keyNavEnabled'> /**
95 </span> * @cfg {Boolean} keyNavEnabled
96 * Specifies whether the up and down arrow keys should trigger spinning up and down. Defaults to true.
100 <span id='Ext-form-field-Spinner-cfg-mouseWheelEnabled'> /**
101 </span> * @cfg {Boolean} mouseWheelEnabled
102 * Specifies whether the mouse wheel should trigger spinning up and down while the field has focus.
105 mouseWheelEnabled: true,
107 <span id='Ext-form-field-Spinner-cfg-repeatTriggerClick'> /**
108 </span> * @cfg {Boolean} repeatTriggerClick
109 * Whether a {@link Ext.util.ClickRepeater click repeater} should be attached to the spinner buttons.
112 repeatTriggerClick: true,
114 <span id='Ext-form-field-Spinner-method-onSpinUp'> /**
117 * This method is called when the spinner up button is clicked, or when the up arrow key is pressed if
118 * {@link #keyNavEnabled} is true. Must be implemented by subclasses.
120 onSpinUp: Ext.emptyFn,
122 <span id='Ext-form-field-Spinner-method-onSpinDown'> /**
125 * This method is called when the spinner down button is clicked, or when the down arrow key is pressed if
126 * {@link #keyNavEnabled} is true. Must be implemented by subclasses.
128 onSpinDown: Ext.emptyFn,
130 initComponent: function() {
134 <span id='Ext-form-field-Spinner-event-spin'> /**
135 </span> * @event spin
136 * Fires when the spinner is made to spin up or down.
137 * @param {Ext.form.field.Spinner} this
138 * @param {String} direction Either 'up' if spinning up, or 'down' if spinning down.
142 <span id='Ext-form-field-Spinner-event-spinup'> /**
143 </span> * @event spinup
144 * Fires when the spinner is made to spin up.
145 * @param {Ext.form.field.Spinner} this
149 <span id='Ext-form-field-Spinner-event-spindown'> /**
150 </span> * @event spindown
151 * Fires when the spinner is made to spin down.
152 * @param {Ext.form.field.Spinner} this
158 <span id='Ext-form-field-Spinner-method-onRender'> /**
162 onRender: function() {
166 me.callParent(arguments);
167 triggers = me.triggerEl;
169 <span id='Ext-form-field-Spinner-property-spinUpEl'> /**
170 </span> * @property {Ext.Element} spinUpEl
171 * The spinner up button element
173 me.spinUpEl = triggers.item(0);
174 <span id='Ext-form-field-Spinner-property-spinDownEl'> /**
175 </span> * @property {Ext.Element} spinDownEl
176 * The spinner down button element
178 me.spinDownEl = triggers.item(1);
180 // Set initial enabled/disabled states
181 me.setSpinUpEnabled(me.spinUpEnabled);
182 me.setSpinDownEnabled(me.spinDownEnabled);
184 // Init up/down arrow keys
185 if (me.keyNavEnabled) {
186 me.spinnerKeyNav = Ext.create('Ext.util.KeyNav', me.inputEl, {
194 if (me.mouseWheelEnabled) {
195 me.mon(me.bodyEl, 'mousewheel', me.onMouseWheel, me);
199 <span id='Ext-form-field-Spinner-method-getTriggerWidth'> /**
201 * Override. Since the triggers are stacked, only measure the width of one of them.
203 getTriggerWidth: function() {
204 return this.hideTrigger || this.readOnly ? 0 : this.spinUpEl.getWidth() + this.triggerWrap.getFrameWidth('lr');
207 <span id='Ext-form-field-Spinner-method-onTrigger1Click'> /**
209 * Handles the spinner up button clicks.
211 onTrigger1Click: function() {
215 <span id='Ext-form-field-Spinner-method-onTrigger2Click'> /**
217 * Handles the spinner down button clicks.
219 onTrigger2Click: function() {
223 <span id='Ext-form-field-Spinner-method-spinUp'> /**
224 </span> * Triggers the spinner to step up; fires the {@link #spin} and {@link #spinup} events and calls the
225 * {@link #onSpinUp} method. Does nothing if the field is {@link #disabled} or if {@link #spinUpEnabled}
230 if (me.spinUpEnabled && !me.disabled) {
231 me.fireEvent('spin', me, 'up');
232 me.fireEvent('spinup', me);
237 <span id='Ext-form-field-Spinner-method-spinDown'> /**
238 </span> * Triggers the spinner to step down; fires the {@link #spin} and {@link #spindown} events and calls the
239 * {@link #onSpinDown} method. Does nothing if the field is {@link #disabled} or if {@link #spinDownEnabled}
242 spinDown: function() {
244 if (me.spinDownEnabled && !me.disabled) {
245 me.fireEvent('spin', me, 'down');
246 me.fireEvent('spindown', me);
251 <span id='Ext-form-field-Spinner-method-setSpinUpEnabled'> /**
252 </span> * Sets whether the spinner up button is enabled.
253 * @param {Boolean} enabled true to enable the button, false to disable it.
255 setSpinUpEnabled: function(enabled) {
257 wasEnabled = me.spinUpEnabled;
258 me.spinUpEnabled = enabled;
259 if (wasEnabled !== enabled && me.rendered) {
260 me.spinUpEl[enabled ? 'removeCls' : 'addCls'](me.trigger1Cls + '-disabled');
264 <span id='Ext-form-field-Spinner-method-setSpinDownEnabled'> /**
265 </span> * Sets whether the spinner down button is enabled.
266 * @param {Boolean} enabled true to enable the button, false to disable it.
268 setSpinDownEnabled: function(enabled) {
270 wasEnabled = me.spinDownEnabled;
271 me.spinDownEnabled = enabled;
272 if (wasEnabled !== enabled && me.rendered) {
273 me.spinDownEl[enabled ? 'removeCls' : 'addCls'](me.trigger2Cls + '-disabled');
277 <span id='Ext-form-field-Spinner-method-onMouseWheel'> /**
279 * Handles mousewheel events on the field
281 onMouseWheel: function(e) {
285 delta = e.getWheelDelta();
289 else if (delta < 0) {
296 onDestroy: function() {
297 Ext.destroyMembers(this, 'spinnerKeyNav', 'spinUpEl', 'spinDownEl');