#25481: Documentation: Add field.help_text to looping over a form's fields
--------------------------------------+------------------------------------
Reporter: wimfeijen | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Old description:
> On https://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-
> form-s-fields
>
> the example of looping over the form's fields omits {{ field.help_text
> }}, though this field is outputted by default by {{ form.as_ul }}. I
> believe we should add {{ field.help_text }} in the example to be both
> consistent and complete.
>
> In addition, but not related, {{ field.errors }} might need a span for
> the example to be usable in real life.
>
> From the docs:
> ---
> Looping over the form’s fields¶
>
> If you’re using the same HTML for each of your form fields, you can
> reduce duplicate code by looping through each field in turn using a {%
> for %} loop:
>
> {{{
> {% for field in form %}
> <div class="fieldWrapper">
> {{ field.errors }}
> {{ field.label_tag }} {{ field }}
> </div>
> {% endfor %}
>
> {% for field in form %}
> <div class="fieldWrapper">
> {{ field.errors }}
> {{ field.label_tag }} {{ field }}
> </div>
> {% endfor %}
> }}}
New description:
On https://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-
form-s-fields
The example of looping over the form's fields omits `{{ field.help_text
}}`, though this field is outputted by default by `{{ form.as_ul }}`. I
believe we should add `{{ field.help_text }}` in the example to be both
consistent and complete.
From the docs:
---
Looping over the form’s fields
If you’re using the same HTML for each of your form fields, you can reduce
duplicate code by looping through each field in turn using a {% for %}
loop:
{{{
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }} {{ field }}
</div>
{% endfor %}
}}}
--
Comment:
It seems there are many other examples on that page that could also be
updated similarly. Did you single this one out for any reason? I don't
know that it's really necessary, but I don't have a great argument against
it besides it will be a bit repetitive in all the examples, especially if
the implementation is something like `{% if field.help_text %}<p>{{
field.help_text }}</p>{% endif %}` so we don't output empty paragraph
elements.
I removed the "In addition, but unrelated" issue from the description as I
don't think there's a need to complicate the example with a particular
HTML structure. ("`{{ field.errors }}` might need a span for the example
to be usable in real life.") `{{ field.errors }}` already includes a
`<ul>` which can be styled, correct?
--
Ticket URL: <https://code.djangoproject.com/ticket/25481#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.bff83a2327d5e197c7837f42b8d315e1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.