-
Notifications
You must be signed in to change notification settings - Fork 125
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
Enter a valid date/time. #77
Comments
Same here, maybe this is an issue with different localizations / conversion between localizations?! EDIT: Solution (?): Specify input format for the DateField:
Now I specify the localized date format and it works for me. Is it possible to specify this automatically!? |
I'm also having this problem. If I leave the widget format as the default, the day and month are swapped when saved, if I try to specify any sort of format in the widget, I get the error "Enter a valid date/time." |
The datewidget simply passes a string (as given on the UI) to the DateField. The DateField first checks if it got a datetime.date(time), which is not the case. Then it tries to parse the string by testing different format specifiers. In my case the format specifier used by the datewidget was not defined in the DateField, so I defined this by hand (see above). What's not so nice is that you would need to specify a format for the DateField for each possible localization, this should somehow work automatically, e.g. if the datewidget did not pass a string but already a datetime.date object. I assume that the swapping of day and month is because e.g. datewidget use "%d/%m/%Y" and DateField assumes "%m/%d/%Y". In my case I only have one localization so it's ok for now. |
The problem in init method of PickerWidgetMixin when language string converted to js objects. Init in django enviroment with following code date_start = forms.DateTimeField(label=_("Date Start"), widget=DateTimeWidget(usel10n=True, bootstrap_version=3), required=False) called only once, when application loading, and not per request. Actually now, with example from documentation django-datetime-widget does not support locale changes per requests, you need to manually call widget initialization per request to change locale of widget and have true support of l18n. I think this is main problem of ValidationErrors on l18n-enabled sites. |
Great catch, I suspect this is my fault from my opinionated refactor a while back. I moved some of the code into the |
This class works fine for me on l18n-enabled site.
|
While using DateTimeInput (default for admin) it actually splits the date and time fields as id_fieldName_0 as date field and id_fieldName_1 as time field. When this DateTimeWidget is used, the post data contains only fieldName as single value, when django expects list of values. Hence in django admin, DateTimeWidget will always throw ValidationError to send values as list. (Tested in Django 1.8 with l10n false in settings) |
Is there a fix for this? I'm getting this error with a DateTimeField and looking at this comment thread I'm no closer to finding a fix. Update: Seems the widget is adding apostrophes around the value e.g. "'2016-03-21 11:00:00'" which is causing the validation failure. Is there anyway to disable this? |
Hi I have setup a form widget like
dt = forms.DateTimeField("Export start time",
widget=DateTimeWidget(usel10n=True, bootstrap_version=3))
The format I chose in formats.py is chosen correctly. I can change the format and the widget changes
when choosing a date. On submit though I always get "Enter a valid date/time."
Any suggestions ?
Thanks
The text was updated successfully, but these errors were encountered: