]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: onClose callback should be triggered by show. Fixed #6656 - onClose event...
authorKato Kazuyoshi <kato.kazuyoshi@gmail.com>
Fri, 6 May 2011 20:58:06 +0000 (05:58 +0900)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Wed, 18 May 2011 14:03:13 +0000 (16:03 +0200)
(cherry picked from commit 2063a113d6dbae006413896a93d46a34ebc9b155)

tests/unit/datepicker/datepicker.html
tests/unit/datepicker/datepicker_events.js
ui/jquery.ui.datepicker.js

index db1f0a55fc89278aa7e9845ce47e5cbb85ac7e69..f297265c36af000ebb58c7be9d002c8db3cab764 100644 (file)
@@ -48,6 +48,7 @@
 
 <div id="main" style="position: absolute; top: -10000px; left: -10000px;">
        <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>
index 0c207097ad2e349883d896d9aa4f2eff9f5279a4..858cf682a11f69c304f41debf7511d0ae7eab2f1 100644 (file)
@@ -117,6 +117,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);
index e6ca5d984af38b4d23256b0f4d870bb0de563b6d..045fa1d92d835d2057aa1794daa3d6345f66081e 100644 (file)
@@ -614,6 +614,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');
@@ -757,6 +760,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) {
@@ -777,10 +788,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) {