Skip to content
Permalink
Browse files

Datepicker: Added onSelect.apply() call to _setDate method if onSelec…

…t is defined. Fixed #6264 - Datepicker: onSelect does not fire when setDate is called
  • Loading branch information...
marcneuwirth authored and gnarf committed Jun 28, 2011
1 parent a56aa86 commit effdd5d19c534f8445ebafe4212278c4366b0041
Showing with 18 additions and 0 deletions.
  1. +10 −0 tests/unit/datepicker/datepicker_options.js
  2. +8 −0 ui/jquery.ui.datepicker.js
@@ -469,6 +469,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() {
@@ -1399,6 +1399,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. */

0 comments on commit effdd5d

Please sign in to comment.
You can’t perform that action at this time.