-
Notifications
You must be signed in to change notification settings - Fork 1k
with dateFormat option, cannot edit datetime using keyboard #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That is because datepicker accepts all input when D or M are used in the dateFormat. In those cases, $.datepicker._possibleChars returns null, which timepicker doesn't catch. diff --git a/jquery-ui-timepicker-addon.js b/jquery-ui-timepicker-addon.js
index 191e2ac..a41dbd4 100644
--- a/jquery-ui-timepicker-addon.js
+++ b/jquery-ui-timepicker-addon.js
@@ -804,7 +804,7 @@ $.datepicker._updateDatepicker = function(inst) {
};
//#######################################################################################
-// third bad hack :/ override datepicker so it allows spaces and colan in the input field
+// third bad hack :/ override datepicker so it allows spaces and colon in the input field
//#######################################################################################
$.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
$.datepicker._doKeyPress = function(event) {
@@ -814,6 +814,7 @@ $.datepicker._doKeyPress = function(event) {
if (tp_inst) {
if ($.datepicker._get(inst, 'constrainInput')) {
var ampm = tp_inst._defaults.ampm,
+ dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
datetimeChars = tp_inst._defaults.timeFormat.toString()
.replace(/[hms]/g, '')
.replace(/TT/g, ampm ? 'APM' : '')
@@ -825,9 +826,9 @@ $.datepicker._doKeyPress = function(event) {
" " +
tp_inst._defaults.separator +
tp_inst._defaults.timeSuffix +
- $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
+ dateChars,
chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
- return event.ctrlKey || (chr < ' ' || !datetimeChars || datetimeChars.indexOf(chr) > -1);
+ return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
}
} As far as I can tell, datetimeChars cannot be null. So I just went ahead and replaced !datetimeChars with !dateChars, which shouldn't be an issue, but I might be wrong here. |
Fix applied to dev |
Thanks for fix, can confirm it works. A work-around for versions without fix is to set 'constrainInput' option to False |
If using month short or long name in date format e.g.
$(selector).datetimepicker({ dateFormat: 'dd MM yy' });
it is not possible to edit the previously entered datetime using keyboard, I have to use the timepicker
E.g. I set field to "10 Jun 2011 16:57" using timepicker and then try to change time to 16:58 by deleting the 7 and pressing "8".
The delete works but 8 is not enetered
The jQuery UI Datepicker function does not have this problem.
The text was updated successfully, but these errors were encountered: