]> source.dussan.org Git - jquery-ui.git/commitdiff
Datepicker: Added onSelect.apply() call to _setDate method if onSelect is defined...
authormarcneuwirth <marc.neuwirth@gmail.com>
Tue, 28 Jun 2011 15:59:08 +0000 (10:59 -0500)
committerCorey Frang <gnarf@gnarf.net>
Tue, 28 Jun 2011 16:00:06 +0000 (11:00 -0500)
(cherry picked from commit effdd5d19c534f8445ebafe4212278c4366b0041)

tests/unit/datepicker/datepicker_options.js
ui/jquery.ui.datepicker.js

index b14c87b8bcb70acdb6cfdf53cc48fda44df7e5f6..a6d4b8fbc6fd06b3a64a678a1d053c5bbd8ae3ea 100644 (file)
@@ -474,6 +474,16 @@ test('setDate', function() {
        var dateAndTimeClone = new Date(2008, 3 - 1, 28, 1, 11, 0);
        inp.datepicker('setDate', dateAndTimeToSet);
        equals(dateAndTimeToSet.getTime(), dateAndTimeClone.getTime(), 'Date object passed should not be changed by setDate');
+    // Test onSelect callback is executed when using setDate
+    inp.datepicker('destroy');
+    var testDate = null;
+    inp.datepicker({
+        onSelect: function(dateText, inst) {
+            testDate = new Date(dateText);
+        }
+    });
+    inp.datepicker('setDate', date2);
+    equals(date2.getTime(), testDate.getTime(), 'onSelect is called after setDate');
 });
 
 test('altField', function() {
index 458ad01eccbe3d4a848189c9d5fcb6164244db90..3f3e73a70bfe81f73d0c4beba5d8f944ade699ea 100644 (file)
@@ -1386,6 +1386,14 @@ $.extend(Datepicker.prototype, {
                if (inst.input) {
                        inst.input.val(clear ? '' : this._formatDate(inst));
                }
+
+               var onSelect = this._get(inst, 'onSelect');
+               if (onSelect) {
+                       var dateStr = this._formatDate(inst);
+
+                       // trigger custom callback
+                       onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
+               }
        },
 
        /* Retrieve the date(s) directly. */