Skip to content
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

Implementation of DateInput widget should render hardcoded "%Y-%m-%d" format #115

Closed
bmihelac opened this issue Jul 10, 2014 · 6 comments · Fixed by #124
Closed

Implementation of DateInput widget should render hardcoded "%Y-%m-%d" format #115

bmihelac opened this issue Jul 10, 2014 · 6 comments · Fixed by #124

Comments

@bmihelac
Copy link
Contributor

Implementation of DateInput widget should render hardcoded "%Y-%m-%d" format.

  1. In Django > 1.6 ISO formats are automatically appended to the list of input formats, unless they are not at first position. (see django/django@90d3af3)
  2. floppyforms DateInput and DateTimeInput both uses first available format which is often not required "%Y-%m-%d" format.
    (https://github.com/gregmuellegger/django-floppyforms/blob/master/floppyforms/widgets.py#L279)

This renders date input as empty in browsers that support date html5 type, requiring user to enter date again:

<input type="date" name="date_of_birth" value="10.07.2014" required="" class="dateinput form-control" id="id_date_of_birth">

That in chrome renders as "dd/mm/yyyy" instead of "10/07/2014", client validation will not allow form to submit if it is required field and would set field to None if it is not required field, thus loosing information.

I propose that DateInput widget always render value in rfc3339 format.

Reference: #27

@gregmuellegger
Copy link
Collaborator

Hi Bojan,

I think that's a valid concern and since a decission was already made in #27 I'm all in on only outputting the iso format for DateInput, DateTimeInput, and TimeInput. I would allow one exception, which is if the user passes in the format argument into the widget's __init__ method.

Just to confirm this that I'm on the same page: floppyforms already used to output only the ISO formats, but Django changed the semantics (the position of the ISO format) of django.utils.formats.get_format a bit so that we need to catch up with this development, right?

If that's the case we should go for a fix on this.
However I'm quite short with time at the moment (in that regard, sorry for the delay till I responded on this issue), I would really appreciate if you could make the first step there and implement a draft as a pull request.

At best it would include some tests and even some documentation on this. But if that's too much to ask for it would even be already a big help if you could document down what changes you think are needed to resolve this ticket.

@bmihelac
Copy link
Contributor Author

Gregor,

Just to confirm this that I'm on the same page: floppyforms already used to output only the ISO formats, but Django changed the semantics (the position of the ISO format) of django.utils.formats.get_format a bit so that we need to catch up with this development, right?

Yes, django has changed position of ISO format, but before that change, some locales did not include an ISO format at all (https://code.djangoproject.com/ticket/19015).

Also it is not guaranteed that ISO format would be on first (or last) position for given locale, so it should be better to hardcore iso format instead of relying on its position in DATE_INPUT_FORMATS.

I would prepare pull request for this so we can discuss this further.

@gregmuellegger
Copy link
Collaborator

I agree, explicitly using the ISO format would be good here.
Thanks so much for taking your effort on this and preparing a pull request!

bmihelac added a commit to bmihelac/django-floppyforms that referenced this issue Sep 7, 2014
bmihelac added a commit to bmihelac/django-floppyforms that referenced this issue Sep 16, 2014
FIX: jazzband#115 - Implementation of DateInput widget should render hardcoded "%Y-%m-%d" format
bmihelac added a commit to bmihelac/django-floppyforms that referenced this issue Sep 16, 2014
bmihelac added a commit to bmihelac/django-floppyforms that referenced this issue Sep 16, 2014
FIX: jazzband#115 - Implementation of DateInput widget should render hardcoded "%Y-%m-%d" format
@bmihelac
Copy link
Contributor Author

Gregor, sorry for delay, here is pull request.

@gregmuellegger
Copy link
Collaborator

Fixed as with #124

@gregmuellegger
Copy link
Collaborator

FYI: I just released floppyforms 1.3 including your changes.

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

Successfully merging a pull request may close this issue.

2 participants