Opened 3 years ago

Closed 2 years ago

Last modified 22 months ago

#18777 closed Bug (fixed)

Visualization of date fields as_hidden aren't localized

Reported by: croldan Owned by: ethlinn
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 croldan 3 years ago.

Download all attachments as: .zip

Change History (9)

Changed 3 years ago by croldan

comment:1 Changed 3 years ago by Natim87

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 2 years ago by ethlinn

  • Cc asendecka@… added
  • Keywords sprint2013 added
  • Owner changed from nobody to ethlinn
  • Status changed from new to assigned

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 2 years ago by ethlinn (previous) (diff)

comment:3 Changed 2 years ago by claudep

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 Changed 2 years ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 893d8de6f5d0b6bf23e2ed072e18fe2e012395c6:

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

Thanks croldan for the report.

comment:5 Changed 2 years ago by Tim Graham <timograham@…>

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 Changed 22 months ago by aaugustin

This fix triggered a regression: #21074.

comment:7 Changed 22 months ago by Florian Apolloner <florian@…>

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 Changed 22 months ago by Florian Apolloner <florian@…>

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