Opened 10 years ago

Last modified 9 years ago

#24347 closed Bug

parameter 'widget' of BoundField.as_widget is ignored — at Version 8

Reported by: Sven R. Kunze Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords: BoundField, as_widget, hidden, initial, hidden_initial
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: yes

Description (last modified by Sven R. Kunze)

'as_widget' has the parameter 'widget' which renders the field. However, this parameter is not used all the time during the 'as_widget' call.

The method 'data', which is (indirectly via 'value') called by 'as_widget', ALWAYS uses the default widget of the field which leads to issues like formatting etc.

We recognized this issue when using 'show_hidden_initial=True' and widgets for datetime objects.

The problem can also be observed when using BoundField.as_hidden as it uses 'as_widget' as well.

cf.
as_widget: https://github.com/django/django/blob/1.8a1/django/forms/forms.py#L566
data: https://github.com/django/django/blob/1.8a1/django/forms/forms.py#L609
as_hidden: https://github.com/django/django/blob/1.8a1/django/forms/forms.py#L602

Versions: 1.4, 1.5, 1.6, 1.7, 1.8, master

Change History (8)

comment:1 by Sven R. Kunze, 10 years ago

Description: modified (diff)

comment:2 by Sven R. Kunze, 10 years ago

Description: modified (diff)

comment:3 by Sven R. Kunze, 10 years ago

Description: modified (diff)
Needs tests: set
Version: master1.8alpha1

in reply to:  description ; comment:4 by Claude Paroz, 10 years ago

Resolution: needsinfo
Status: newclosed

Replying to srkunze:

'as_widget' has the parameter 'widget' which renders the field. However, this parameter is not used all the time during the 'as_widget' call.

Sorry, but that's not true. The widget parameter is used in widget.render(...) at the end of the method. It's totally possible something is not working properly, but then we'll need a more thorough example to demonstrate the issue.

in reply to:  4 comment:5 by Sven R. Kunze, 10 years ago

Replying to claudep:

The widget parameter is used in widget.render(...) at the end of the method.

I am not saying that this is the only possible place where the widget is used.

It's totally possible something is not working properly,

Please, carefully read my ticket again as I described what's wrong:

The method 'data', which is (indirectly via 'value') called by 'as_widget' ALWAYS used the default widget of the field which leads to issues like formatting etc.

but then we'll need a more thorough example to demonstrate the issue.

Cf. my ticket again:

The problem can also be observed when using BoundField.as_hidden as it uses 'as_widget' as well.

BouldField.as_hidden should always use the HiddenWidget during processing BoundField.as_widget, but BouldField.data uses the default widget which is not the HiddenWidget of course.

A more concise presentation of the issue:

`BoundField.as_hidden` -> `BoundField.as_widget` -> `BoundField.value` -> `BoundField.data`
(wants HiddenWidget)      (uses HiddenWidget)       (uses default widget) (uses default widget)

"->" means "uses"

BoundField.as_hidden specifies the HiddenWidget when it calls BoundField.as_widget
BoundField.value and BoundField.data do not respect the specified widget

Hence, the output is flawed.

Last edited 10 years ago by Sven R. Kunze (previous) (diff)

comment:6 by Sven R. Kunze, 10 years ago

Resolution: needsinfo
Status: closednew

comment:7 by Sven R. Kunze, 10 years ago

Description: modified (diff)

comment:8 by Sven R. Kunze, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top