Skip to content

Commit

Permalink
Datepicker: Added onSelect.apply() call to _doKeyDown method when ent…
Browse files Browse the repository at this point in the history
…er button pushed if onSelect is defined. Fixed #7124 - Datepicker: onSelect does not fire when enter button is pushed

(cherry picked from commit a56aa86)
  • Loading branch information
marcneuwirth authored and gnarf committed Jun 28, 2011
1 parent 86a09ae commit bb9f9fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/unit/datepicker/datepicker_events.js
Expand Up @@ -46,6 +46,11 @@ test('events', function() {
simulate('keydown', {keyCode: $.simulate.VK_ESC});
equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date),
'Callback selected date - esc');
var dateStr = '02/04/2008';
inp.val(dateStr).datepicker('show').
simulate('keydown', {keyCode: $.simulate.VK_ENTER});
equals(dateStr, selectedDate,
'onSelect is called after enter keydown');
// onChangeMonthYear
inp.datepicker('option', {onChangeMonthYear: callback2, onSelect: null}).
val('').datepicker('show');
Expand Down
7 changes: 7 additions & 0 deletions ui/jquery.ui.datepicker.js
Expand Up @@ -520,6 +520,13 @@ $.extend(Datepicker.prototype, {
$.datepicker._currentClass + ')', inst.dpDiv);
if (sel[0])
$.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]);
var onSelect = $.datepicker._get(inst, 'onSelect');
if (onSelect) {
var dateStr = $.datepicker._formatDate(inst);

// trigger custom callback
onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
}
else
$.datepicker._hideDatepicker();
return false; // don't submit the form
Expand Down

0 comments on commit bb9f9fa

Please sign in to comment.