Skip to content

Commit 9998030

Browse files
Add enable and disable feature by wallenium. Feature not yet stable but doesnt impact rest of plugin
1 parent 5d05d23 commit 9998030

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ function Timepicker() {
6565
secondGrid: 0,
6666
alwaysSetTime: true,
6767
separator: ' ',
68-
altFieldTimeOnly: true
68+
altFieldTimeOnly: true,
69+
showTimepicker: true
6970
};
7071
$.extend(this._defaults, this.regional['']);
7172
}
@@ -253,7 +254,8 @@ $.extend(Timepicker.prototype, {
253254
dp_id = this.inst.id.toString().replace(/([^A-Za-z0-9_])/g, '');
254255

255256
// Prevent displaying twice
256-
if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) {
257+
//if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) {
258+
if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) {
257259
var noDisplay = ' style="display:none;"',
258260
html = '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' +
259261
'<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' +
@@ -632,8 +634,10 @@ $.extend(Timepicker.prototype, {
632634
}
633635

634636
this.formattedDateTime = formattedDateTime;
635-
636-
if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
637+
638+
if(!this._defaults.showTimepicker) {
639+
this.$input.val(this.formattedDate);
640+
} else if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
637641
this.$altInput.val(this.formattedTime);
638642
this.$input.val(this.formattedDate);
639643
} else if(this.$altInput) {
@@ -784,6 +788,29 @@ $.datepicker._gotoToday = function(id) {
784788
this._setTime(this._getInst($(id)[0]), new Date());
785789
};
786790

791+
//#######################################################################################
792+
// Disable & enable the Time in the datetimepicker
793+
//#######################################################################################
794+
$.datepicker._disableTimepickerDatepicker = function(target, date, withDate) {
795+
var inst = this._getInst(target),
796+
tp_inst = this._get(inst, 'timepicker');
797+
if (tp_inst) {
798+
tp_inst._defaults.showTimepicker = false;
799+
tp_inst._onTimeChange();
800+
tp_inst._updateDateTime(inst);
801+
}
802+
};
803+
804+
$.datepicker._enableTimepickerDatepicker = function(target, date, withDate) {
805+
var inst = this._getInst(target),
806+
tp_inst = this._get(inst, 'timepicker');
807+
if (tp_inst) {
808+
tp_inst._defaults.showTimepicker = true;
809+
tp_inst._onTimeChange();
810+
tp_inst._updateDateTime(inst);
811+
}
812+
};
813+
787814
//#######################################################################################
788815
// Create our own set time function
789816
//#######################################################################################

0 commit comments

Comments
 (0)