Skip to content

Date not read from field when using jQuery UI v1.8.14 #197

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

Open
mabeyj opened this issue Jul 7, 2011 · 7 comments
Open

Date not read from field when using jQuery UI v1.8.14 #197

mabeyj opened this issue Jul 7, 2011 · 7 comments

Comments

@mabeyj
Copy link

mabeyj commented Jul 7, 2011

If you click on a field that already holds a date/time value, the date/time picker displays today's date instead of the date in the field's value. The time is read correctly. This only happens when using jQuery UI v1.8.14. Tested in Chrome 12 and Firefox 5.

Test case: http://jsfiddle.net/jmabey/zrhfd/

Notice the date is set to 01/02/2012, but when you click the field, today's date is selected.

@rherriman
Copy link

I've been fighting this issue all day. Great timing! I thought I was going crazy.

No amount of fidgeting with datepicker options seems to get around this issue. Worth noting, perhaps, that setting a defaultDate to $(this).val().split(' ')[0] does seem to stick. Of course, if a new date is selected, obviously the original date continues to pop-up on subsequent datetimepicker "openings" (as is the expected behavior).

Still an issue on jQuery 1.6.2, as well (jmabey's test case uses 1.6.1 it looks like).

@jabouillei
Copy link

I just put in a pull request for a fix. I'm very, very new to jQuery and github, so I'm not sure I've followed all the proper procedures to get the fix in. FWIW, here is what I requested be added:

//#######################################################################################
// override parseDate() because UI 1.8.14 throws an error about "Extra characters"
// An option in datapicker to ignore extra format characters would be nicer.
//#######################################################################################
$.datepicker._base_parseDate = $.datepicker.parseDate;
$.datepicker.parseDate = function(format, value, settings) {
var date;
try {
date = this._base_parseDate(format, value, settings);
} catch (err) {
// Hack! The error message ends with a colon, a space, and
// the "extra" characters. We rely on that instead of
// attempting to perfectly reproduce the parsing algorithm.
date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings);
}
return date;
};

@domenkozar
Copy link

Patch does not help to me :) Date does not get recognized correctly.

@jabouillei
Copy link

Patch does not help to me :) Date
does not get recognized correctly.

What is an example date that is not recognized?

  • Todd

@domenkozar
Copy link

jquery: 1.5.1
jquery.ui: 1.8.14

Datetimepicker settings:

dateFormat: %Y/%m/%d
timeFormat: %H:%M

Steps to reproduce:

  • set date in input to something else than today (eg 2001/01/01)
  • open datetimepicker, date will be still shown as today

@domenkozar
Copy link

I reproduced it in jsfiddle and it seems the patch indeed fixes the problem. Thanks!

@kuzemchik
Copy link

There is validation in _parseDate which throw exception and set current date to 0. To override it it is necessary to send only date to the '_parseDate'. I'll provide patch in an hour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants