jazzband / django-floppyforms

Full control of form rendering in the templates.
http://django-floppyforms.readthedocs.org/
Other
839 stars 145 forks source link

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

Closed bmihelac closed 10 years ago

bmihelac commented 10 years ago

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 https://github.com/django/django/commit/90d3af380e8efec0301dd91600c6686232de3943)
  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: https://github.com/gregmuellegger/django-floppyforms/issues/27

gregmuellegger commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

Gregor, sorry for delay, here is pull request.

gregmuellegger commented 10 years ago

Fixed as with #124

gregmuellegger commented 9 years ago

FYI: I just released floppyforms 1.3 including your changes.