3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * @class Ext.form.SliderField
9 * @extends Ext.form.Field
10 * Wraps a {@link Ext.slider.MultiSlider Slider} so it can be used as a form field.
12 * Creates a new SliderField
13 * @param {Object} config Configuration options. Note that you can pass in any slider configuration options, as well as
14 * as any field configuration options.
17 Ext.form.SliderField = Ext.extend(Ext.form.Field, {
20 * @cfg {Boolean} useTips
21 * True to use an Ext.slider.Tip to display tips for the value. Defaults to <tt>true</tt>.
26 * @cfg {Function} tipText
27 * A function used to display custom text for the slider tip. Defaults to <tt>null</tt>, which will
28 * use the default on the plugin.
36 * Initialize the component.
39 initComponent : function() {
40 var cfg = Ext.copyTo({
41 id: this.id + '-slider'
42 }, this.initialConfig, ['vertical', 'minValue', 'maxValue', 'decimalPrecision', 'keyIncrement', 'increment', 'clickToChange', 'animate']);
44 // only can use it if it exists.
46 var plug = this.tipText ? {getText: this.tipText} : {};
47 cfg.plugins = [new Ext.slider.Tip(plug)];
49 this.slider = new Ext.Slider(cfg);
50 Ext.form.SliderField.superclass.initComponent.call(this);
54 * Set up the hidden field
55 * @param {Object} ct The container to render to.
56 * @param {Object} position The position in the container to render to.
59 onRender : function(ct, position){
66 Ext.form.SliderField.superclass.onRender.call(this, ct, position);
67 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
68 this.resizeEl = this.positionEl = this.wrap;
69 this.slider.render(this.wrap);
73 * Ensure that the slider size is set automatically when the field resizes.
74 * @param {Object} w The width
75 * @param {Object} h The height
76 * @param {Object} aw The adjusted width
77 * @param {Object} ah The adjusted height
80 onResize : function(w, h, aw, ah){
81 Ext.form.SliderField.superclass.onResize.call(this, w, h, aw, ah);
82 this.slider.setSize(w, h);
86 * Initialize any events for this class.
89 initEvents : function(){
90 Ext.form.SliderField.superclass.initEvents.call(this);
91 this.slider.on('change', this.onChange, this);
95 * Utility method to set the value of the field when the slider changes.
96 * @param {Object} slider The slider object.
97 * @param {Object} v The new value.
100 onChange : function(slider, v){
101 this.setValue(v, undefined, true);
105 * Enable the slider when the field is enabled.
108 onEnable : function(){
109 Ext.form.SliderField.superclass.onEnable.call(this);
110 this.slider.enable();
114 * Disable the slider when the field is disabled.
117 onDisable : function(){
118 Ext.form.SliderField.superclass.onDisable.call(this);
119 this.slider.disable();
123 * Ensure the slider is destroyed when the field is destroyed.
126 beforeDestroy : function(){
127 Ext.destroy(this.slider);
128 Ext.form.SliderField.superclass.beforeDestroy.call(this);
132 * If a side icon is shown, do alignment to the slider
135 alignErrorIcon : function(){
136 this.errorIcon.alignTo(this.slider.el, 'tl-tr', [2, 0]);
140 * Sets the minimum field value.
141 * @param {Number} v The new minimum value.
142 * @return {Ext.form.SliderField} this
144 setMinValue : function(v){
145 this.slider.setMinValue(v);
150 * Sets the maximum field value.
151 * @param {Number} v The new maximum value.
152 * @return {Ext.form.SliderField} this
154 setMaxValue : function(v){
155 this.slider.setMaxValue(v);
160 * Sets the value for this field.
161 * @param {Number} v The new value.
162 * @param {Boolean} animate (optional) Whether to animate the transition. If not specified, it will default to the animate config.
163 * @return {Ext.form.SliderField} this
165 setValue : function(v, animate, /* private */ silent){
166 // silent is used if the setValue method is invoked by the slider
167 // which means we don't need to set the value on the slider.
169 this.slider.setValue(v, animate);
171 return Ext.form.SliderField.superclass.setValue.call(this, this.slider.getValue());
175 * Gets the current value for this field.
176 * @return {Number} The current value.
178 getValue : function(){
179 return this.slider.getValue();
183 Ext.reg('sliderfield', Ext.form.SliderField);