Skip to content

Default values #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 28, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions jquery-ui-timepicker-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ function Timepicker() {
timezoneIso8601: false,
timezoneList: null,
addSliderAccess: false,
sliderAccessArgs: null
sliderAccessArgs: null,
defaultValue: null
};
$.extend(this._defaults, this.regional['']);
}
Expand Down Expand Up @@ -229,6 +230,10 @@ $.extend(Timepicker.prototype, {
if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) {
tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
}
tp_inst.$input.bind('focus', function() {
tp_inst._onFocus();
});

return tp_inst;
},

Expand Down Expand Up @@ -861,6 +866,24 @@ $.extend(Timepicker.prototype, {
}

this.$input.trigger("change");
},

_onFocus: function() {
if( !this.$input.val() && this._defaults.defaultValue ) {
this.$input.val(this._defaults.defaultValue);
var inst = $.datepicker._getInst(this.$input.get(0)),
tp_inst = $.datepicker._get(inst, 'timepicker');
if (tp_inst) {
if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
try {
$.datepicker._updateDatepicker(inst);
}
catch (err) {
$.datepicker.log(err);
}
}
}
}
}

});
Expand Down Expand Up @@ -1591,23 +1614,23 @@ $.timepicker.dateRange = function( startTime, endTime, options, method ) {
* @return jQuery
*/
$.timepicker.handleRange = function( method, startTime, endTime, options ) {
$.fn[method].call(startTime, $.extend({}, {
$.fn[method].call(startTime, $.extend({
onClose: function(dateText, inst) {
checkDates(this, endTime, dateText);
},
onSelect: function (selectedDateTime) {
selected(this, endTime, 'minDate');
}
}, options)
}, options, options.start)
);
$.fn[method].call(endTime, $.extend({}, {
$.fn[method].call(endTime, $.extend({
onClose: function(dateText, inst) {
checkDates(this, startTime, dateText);
},
onSelect: function (selectedDateTime) {
selected(this, startTime, 'maxDate');
}
}, options)
}, options, options.end)
);
// timepicker doesn't provide access to its 'timeFormat' option,
// nor could I get datepicker.formatTime() to behave with times, so I
Expand Down