Skip to content

Commit 2063a11

Browse files
committed
Datepicker: onClose callback should be triggered by show. Fixed #6656 - onClose event not triggered.
1 parent 476777f commit 2063a11

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

tests/unit/datepicker/datepicker.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ <h2 id="qunit-userAgent"></h2>
4949

5050
<div id="qunit-fixture">
5151
<p><input type="text" id="inp"/><input type="text" id="alt"/><div id="inl"></div></p>
52+
<p><input type="text" id="inp2"/></p>
5253
</div>
5354

5455
</body>

tests/unit/datepicker/datepicker_events.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ test('events', function() {
112112
inp.val('02/04/2008').datepicker('show').
113113
simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END});
114114
equals(selectedDate, '', 'Callback close date - ctrl+end');
115+
116+
var inp2 = init('#inp2');
117+
inp2.datepicker().datepicker('option', {onClose: callback}).datepicker('show');
118+
inp.datepicker('show');
119+
equals(selectedThis, inp2[0], 'Callback close this');
115120
});
116121

117122
})(jQuery);

ui/jquery.ui.datepicker.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ $.extend(Datepicker.prototype, {
609609
return;
610610
var inst = $.datepicker._getInst(input);
611611
if ($.datepicker._curInst && $.datepicker._curInst != inst) {
612+
if ( $.datepicker._datepickerShowing ) {
613+
$.datepicker._triggerOnClose($.datepicker._curInst);
614+
}
612615
$.datepicker._curInst.dpDiv.stop(true, true);
613616
}
614617
var beforeShow = $.datepicker._get(inst, 'beforeShow');
@@ -754,6 +757,14 @@ $.extend(Datepicker.prototype, {
754757
return [position.left, position.top];
755758
},
756759

760+
/* Trigger custom callback of onClose. */
761+
_triggerOnClose: function(inst) {
762+
var onClose = this._get(inst, 'onClose');
763+
if (onClose)
764+
onClose.apply((inst.input ? inst.input[0] : null),
765+
[(inst.input ? inst.input.val() : ''), inst]);
766+
},
767+
757768
/* Hide the date picker from view.
758769
@param input element - the input field attached to the date picker */
759770
_hideDatepicker: function(input) {
@@ -776,10 +787,7 @@ $.extend(Datepicker.prototype, {
776787
(showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))]((showAnim ? duration : null), postProcess);
777788
if (!showAnim)
778789
postProcess();
779-
var onClose = this._get(inst, 'onClose');
780-
if (onClose)
781-
onClose.apply((inst.input ? inst.input[0] : null),
782-
[(inst.input ? inst.input.val() : ''), inst]); // trigger custom callback
790+
$.datepicker._triggerOnClose(inst);
783791
this._datepickerShowing = false;
784792
this._lastInput = null;
785793
if (this._inDialog) {

0 commit comments

Comments
 (0)