Skip to content
This repository was archived by the owner on Feb 14, 2022. It is now read-only.

Commit a9defa1

Browse files
Add custom controlType example
1 parent 2f9ff08 commit a9defa1

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

index.html

+43
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,49 @@ <h3 id="slider_examples">Slider Modifications</h3>
620620
});</pre>
621621
</div>
622622

623+
<!-- ============= example -->
624+
<div class="example-container">
625+
<p>Create your own control by implementing the create, options, and value methods. If you want to use your new control for all instances use the $.timepicker.setDefaults({controlType:myControl}). Here we implement jQueryUI's spinner control (jQueryUI 1.9+).</p>
626+
<div>
627+
<input type="text" name="slider_example_5" id="slider_example_5" value="" />
628+
</div>
629+
<pre>var myControl= {
630+
create: function(tp_inst, obj, unit, val, min, max, step){
631+
$('&lt;input class="ui-timepicker-input" value="'+val+'" style="width:50%"&gt;')
632+
.appendTo(obj)
633+
.spinner({
634+
min: min,
635+
max: max,
636+
step: step,
637+
change: function(e,ui){ // key events
638+
tp_inst._onTimeChange();
639+
tp_inst._onSelectHandler();
640+
},
641+
spin: function(e,ui){ // spin events
642+
tp_inst.control.value(tp_inst, obj, unit, ui.value);
643+
tp_inst._onTimeChange();
644+
tp_inst._onSelectHandler();
645+
}
646+
});
647+
return obj;
648+
},
649+
options: function(tp_inst, obj, unit, opts, val){
650+
if(typeof(opts) == 'string' && val !== undefined)
651+
return obj.find('.ui-timepicker-input').spinner(opts, val);
652+
return obj.find('.ui-timepicker-input').spinner(opts);
653+
},
654+
value: function(tp_inst, obj, unit, val){
655+
if(val !== undefined)
656+
return obj.find('.ui-timepicker-input').spinner('value', val);
657+
return obj.find('.ui-timepicker-input').spinner('value');
658+
}
659+
};
660+
661+
$('#slider_example_5').datetimepicker({
662+
controlType: myControl
663+
});</pre>
664+
</div>
665+
623666
<h3 id="alt_examples">Alternate Fields</h3>
624667

625668
<!-- ============= example -->

jquery-ui-timepicker-addon.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210

211211
// controlType is string - key to our this._controls
212212
if(typeof(tp_inst._defaults.controlType) === 'string'){
213-
if(tp_inst._defaults.controlType == 'slider' && $.fn.slider === undefined){
213+
if($.fn[tp_inst._defaults.controlType] === undefined){
214214
tp_inst._defaults.controlType = 'select';
215215
}
216216
tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType];

0 commit comments

Comments
 (0)