Skip to content

Commit 95a6ef2

Browse files
committed
Changed _doKeyPress to limit input characters correctly
based on timeFormat + a space + dateFormat (now restricts am/pm correctly based on timeFormat)
1 parent ba7074f commit 95a6ef2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,14 @@ $.datepicker._doKeyPress = function(event) {
608608

609609
if (tp_inst) {
610610
if ($.datepicker._get(inst, 'constrainInput')) {
611-
var datetimeChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')) + "aAmMpP :",
611+
var datetimeChars = tp_inst._defaults.timeFormat.toString()
612+
.replace(/[hms]/g, '')
613+
.replace(/TT|T/g, 'APM')
614+
.replace(/tt|t/g, 'apm') +
615+
" " +
616+
$.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
612617
chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
613-
return event.ctrlKey || (chr < ' ' || !dateChars || dateChars.indexOf(chr) > -1);
618+
return event.ctrlKey || (chr < ' ' || !datetimeChars || datetimeChars.indexOf(chr) > -1);
614619
}
615620
} else return $.datepicker._base_doKeyPress(event);
616621

0 commit comments

Comments
 (0)