[Django] #33437: Add possibility to render fields individually using as_p, a_table and as_ul

4 views
Skip to first unread message

Django

unread,
Jan 13, 2022, 6:28:20 AM1/13/22
to django-...@googlegroups.com
#33437: Add possibility to render fields individually using as_p, a_table and as_ul
--------------------------------------------+------------------------
Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
Currently, to render a form, there is a choice between rendering the form
entirely with:

{{{#!xml
<form action="/your-name/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
}}}

and the more cumberstone solution of
[https://docs.djangoproject.com/en/4.0/topics/forms/#rendering-fields-
manually Rendering fields manually] if you need more flexibility — for
instance if you need to fieldsets like proposed in #6630:

{{{#!xml
<form action="/your-name/" method="post">
{% csrf_token %}
{{ form }}

<div class="fieldWrapper">
{{ form.subject.errors }}
{{ form.subject.label_tag }}
{{ form.subject }}
</div>

<input type="submit" value="Submit">
</form>
}}}

What I propose is a tradeoff where field can be rendered individually
using this simple syntax:

{{{#!xml
<form action="/your-name/" method="post">
{% csrf_token %}
{{ form }}

{{ form.subject.as_p }}

<input type="submit" value="Submit">
</form>
}}}

I opened [https://github.com/django/django/pull/15313 a proposition PR to
solve this feature request].

--
Ticket URL: <https://code.djangoproject.com/ticket/33437>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 13, 2022, 7:23:41 AM1/13/22
to django-...@googlegroups.com
#33437: Add possibility to render fields individually using as_p, a_table and as_ul
----------------------------------+--------------------------------------

Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Hrushikesh Vaidya):

* cc: Hrushikesh Vaidya (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/33437#comment:1>

Django

unread,
Jan 13, 2022, 4:07:36 PM1/13/22
to django-...@googlegroups.com
#33437: Add possibility to render fields individually using as_p, a_table and as_ul
----------------------------------+--------------------------------------

Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by David Smith):

Thank you for your proposal. I have a few comments (mainly concerns,
sorry) on this.

The first is that the current `as_` methods are not recommended due to
accessibility concerns see #32339. I don't think we should be adding
additional features to something that we are not willing to recommend,
even if we stop short of removing the due to backward compatibility
concerns. Having said that it could be appropriate if an `as_div()` render
style is introduced.

I wonder about having the same named functions on both the field and the
form. I'd have thought that would lead to some confusion?

I appreciate this is about whole forms rather than fields is I wonder how
far the new template based form rendering API could meet this need.

--
Ticket URL: <https://code.djangoproject.com/ticket/33437#comment:2>

Django

unread,
Jan 15, 2022, 12:18:00 PM1/15/22
to django-...@googlegroups.com
#33437: Add possibility to render fields individually using as_p, a_table and as_ul
----------------------------------+----------------------------------------
Reporter: Christophe Henry | Owner: since9teen94
Type: New feature | Status: assigned
Component: Forms | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by since9teen94):

* owner: nobody => since9teen94
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33437#comment:3>

Django

unread,
Jan 15, 2022, 12:25:44 PM1/15/22
to django-...@googlegroups.com
#33437: Add possibility to render fields individually using as_p, a_table and as_ul
----------------------------------+--------------------------------------
Reporter: Christophe Henry | Owner: (none)

Type: New feature | Status: new
Component: Forms | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by since9teen94):

* owner: since9teen94 => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/33437#comment:4>

Django

unread,
Jan 17, 2022, 9:44:37 AM1/17/22
to django-...@googlegroups.com
#33437: Add possibility to render fields individually using as_p, a_table and as_ul
----------------------------------+--------------------------------------

Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Christophe Henry):

#32339 mentions discouraging developers from using `<fieldset>` and
`<legend>`, which is the main purpose for this proposition. That begin
said, I get there's not much point in proposing `as_ul` and `as_table`
for fields. I'm opened to suggestions.

--
Ticket URL: <https://code.djangoproject.com/ticket/33437#comment:3>

Django

unread,
Jan 19, 2022, 10:17:34 AM1/19/22
to django-...@googlegroups.com
#33437: Add possibility to render fields individually using as_p, a_table and as_ul
----------------------------------+--------------------------------------

Reporter: Christophe Henry | Owner: nobody
Type: New feature | Status: closed
Component: Forms | Version: 4.0
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => wontfix


Comment:

Hi Christophe. Thanks for the proposal.

I think this would be too much API, for little benefit. As David says,
leaning towards the new template based form rendering is the way to go,
and we're looking at deprecating the various `as_p()` &co methods.

If you wanted this kind of this, and the inbuilt rendering isn't enough
for you, I'd look towards third-party packages (such as Crispy Forms,
Floppy Forms, Django Sniplates, ...and so on) , or adding a custom tag
taking a form field to your own project. (I hope one of those options
helps :)

Thanks again.

--
Ticket URL: <https://code.djangoproject.com/ticket/33437#comment:4>

Reply all
Reply to author
Forward
0 new messages