Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions tests/unit/datepicker/datepicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h2 id="qunit-userAgent"></h2>

<div id="qunit-fixture">
<p><input type="text" id="inp"/><input type="text" id="alt"/><div id="inl"></div></p>
<p><input type="text" id="inp2"/></p>
</div>

</body>
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/datepicker/datepicker_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ test('events', function() {
inp.val('02/04/2008').datepicker('show').
simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END});
equals(selectedDate, '', 'Callback close date - ctrl+end');

var inp2 = init('#inp2');
inp2.datepicker().datepicker('option', {onClose: callback}).datepicker('show');
inp.datepicker('show');
equals(selectedThis, inp2[0], 'Callback close this');
});

})(jQuery);
16 changes: 12 additions & 4 deletions ui/jquery.ui.datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ $.extend(Datepicker.prototype, {
return;
var inst = $.datepicker._getInst(input);
if ($.datepicker._curInst && $.datepicker._curInst != inst) {
if ( $.datepicker._datepickerShowing ) {
$.datepicker._triggerOnClose($.datepicker._curInst);
}
$.datepicker._curInst.dpDiv.stop(true, true);
}
var beforeShow = $.datepicker._get(inst, 'beforeShow');
Expand Down Expand Up @@ -754,6 +757,14 @@ $.extend(Datepicker.prototype, {
return [position.left, position.top];
},

/* Trigger custom callback of onClose. */
_triggerOnClose: function(inst) {
var onClose = this._get(inst, 'onClose');
if (onClose)
onClose.apply((inst.input ? inst.input[0] : null),
[(inst.input ? inst.input.val() : ''), inst]);
},

/* Hide the date picker from view.
@param input element - the input field attached to the date picker */
_hideDatepicker: function(input) {
Expand All @@ -776,10 +787,7 @@ $.extend(Datepicker.prototype, {
(showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))]((showAnim ? duration : null), postProcess);
if (!showAnim)
postProcess();
var onClose = this._get(inst, 'onClose');
if (onClose)
onClose.apply((inst.input ? inst.input[0] : null),
[(inst.input ? inst.input.val() : ''), inst]); // trigger custom callback
$.datepicker._triggerOnClose(inst);
this._datepickerShowing = false;
this._lastInput = null;
if (this._inDialog) {
Expand Down