Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#18777 closed Bug (fixed)

Visualization of date fields as_hidden aren't localized

Reported by: César H. Roldán Owned by: Aleksandra Sendecka
Component: Forms Version: 1.4
Severity: Normal Keywords: date widget hidden sprint2013
Cc: asendecka@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When use a date field as_hidden in template, the value isn't localized.

For example, in my settings.py I set:

LANGUAGE_CODE="es_ar"

and when I use:

{{form.field.as_hidden}}

I recieve:

<input type="hidden" name="date_field" value="2012-01-01" id="id_date_field">

and the correct format must be:

<input type="hidden" name="date_field" value="01/01/2012" id="id_date_field">

The Input widget does not use format for those types (see Date, DateTime or Time widgets)

Attachments (1)

django_date_time_hidden.patch (1.0 KB ) - added by César H. Roldán 12 years ago.

Download all attachments as: .zip

Change History (9)

by César H. Roldán, 12 years ago

comment:1 by Natim87, 12 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Aleksandra Sendecka, 12 years ago

Cc: asendecka@… added
Keywords: sprint2013 added
Owner: changed from nobody to Aleksandra Sendecka
Status: newassigned

The problem here is much deeper. The same behavior is for any field that had to be localized (for example decimal field). It turned out that if we call functions such as as_hidden or as_text on a field, the value will not be localized. The fix is on the Field level: prepare_value method checks if the widget has 'is_localized' set to True and if so, runs formats.localize_input(value).

The patch is here:
https://github.com/django/django/pull/825

Last edited 12 years ago by Aleksandra Sendecka (previous) (diff)

comment:3 by Claude Paroz, 12 years ago

Note that this is also related to #16612, where changed value detection is not properly handled for localized value. I suggest to commit this one only after #16612 is fixed.

comment:4 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 893d8de6f5d0b6bf23e2ed072e18fe2e012395c6:

Fixed #18777 -- Localized form fields with as_text/as_hidden

Thanks croldan for the report.

comment:5 by Tim Graham <timograham@…>, 11 years ago

In 6e4fd816c48b6ffd06fb7ae2c8ef2009bb0c6c25:

[1.6.x] Fixed #18777 -- Localized form fields with as_text/as_hidden

Thanks croldan for the report.

Backport of 893d8de6f5 from master

comment:6 by Aymeric Augustin, 11 years ago

This fix triggered a regression: #21074.

comment:7 by Florian Apolloner <florian@…>, 11 years ago

In 56743cf9e337826e4c615909570bb057142a6a7b:

Ensured that BoundField.as_widget always returns properly localized fields.

This is a follow-up to #18777 which improperly converted to strings in
prepare_value and as such caused regressions like #21074.

Refs #18777, #21074

comment:8 by Florian Apolloner <florian@…>, 11 years ago

In ece8d6521771635fb5e15d1093524b4f848608fa:

[1.6.x] Ensured that BoundField.as_widget always returns properly localized fields.

This is a follow-up to #18777 which improperly converted to strings in
prepare_value and as such caused regressions like #21074.

Refs #18777, #21074

Backport of 56743cf9e337826e4c615909570bb057142a6a7b from master.

Note: See TracTickets for help on using tickets.
Back to Top