#34426 closed New feature (duplicate)

Pass the BoundField instance to the Widget.render

Reported by: Christophe Henry Owned by: nobody
Component: Forms Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django 4's form rendering API is nice, but lacking a important feature to me: the Widget used to render a particular Field doesn't have any access to the corresponding BoundField. This makes rendering the field, label, potential error messages altogether as well as more more complex structures — like fields with subfields, for instance — impossible to render atomically within the widget. If you want to do that, you're forced to go up to the Form's template itself.

My opinion is that `Widget.render` should be passed the corresponding BoundField instance.

This would, I think, have 2 benefits:

  1. allow easier rendering of complex widgets like ChoiceWidget using an iteration on the BoundField (which is what's documented and would allow unification with ChoiceWidget.options and ChoiceWidget.optgroups)
  1. allow rendering together Form fields that are related since BoundField has access to the parent Form (for instance a form with three options: email, phone, and other, respectively related to an email input, a phone input and a text input that are displayed below each).


P.S.: This is a feature request but I'm still opening a bug here since I can't join the django-developers mailing-list without a Google account.

Change History (1)

comment:1 by Mariusz Felisiak, 21 months ago

Resolution: duplicate
Status: newclosed

Duplicate of #33166 (see also #34077).

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