Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25481 closed Cleanup/optimization (fixed)

Documentation: Add field.help_text to looping over a form's fields

Reported by: Wim Feijen Owned by: John Moses
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Tim Graham)

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 %}

Change History (6)

comment:1 by Tim Graham, 9 years ago

Description: modified (diff)
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

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?

comment:2 by John Moses, 9 years ago

Owner: changed from nobody to John Moses
Status: newassigned

comment:3 by John Moses, 9 years ago

Updated documentation and submitted pull request: https://github.com/django/django/pull/5383
Please let me know if am I missing anything.
Thanks.

comment:4 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In ac09d22f:

Fixed #25481 -- Added field.help_text to "Looping over a form's fields" docs.

comment:5 by Tim Graham <timograham@…>, 9 years ago

In a9b62189:

[1.8.x] Fixed #25481 -- Added field.help_text to "Looping over a form's fields" docs.

Backport of ac09d22f7913ff09f98001ff51b783932290e378 from master

comment:6 by Tim Graham <timograham@…>, 9 years ago

In 6a582d3:

[1.9.x] Fixed #25481 -- Added field.help_text to "Looping over a form's fields" docs.

Backport of ac09d22f7913ff09f98001ff51b783932290e378 from master

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