#31158: _password_validators_help_text_html() returns HTML block level element
-----------------------------------------+------------------------
Reporter: Carsten Fuchs | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 3.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 |
-----------------------------------------+------------------------
In `django.contrib.auth.password_validation`, function
`_password_validators_help_text_html()` returns a `<ul>` list, which is an
HTML block level element. (If I understood it correctly, this was
introduced in #26097.) This list is used as the `help_text` of a related
form field.
Imho, from the view of a template author for rendering the form, getting a
`<ul>` here is somewhat unexpected:
- Help texts are usually brief, one line statements that are written
inline in Field constructors calls; the Django documentation has numerous
examples.
- The documentation of `help_text` seems to expect such simple texts as
well: https://docs.djangoproject.com/en/3.0/ref/forms/fields/#help-text
shows the form rendered with `f.as_p()` at the bottom of the example.
- In many form (template) examples that I can find, including
Bootstrap's, `{{ field.help_text }}` is usually wrapped in `<p>` or
`<small>` elements.
As having block level elements in `<p>` or `<small>` is invalid HTML, I
suggest to join the strings of the password validators with a simple
`<br>` instead. For example:
{{{
#!python
def _password_validators_help_text_html(password_validators=None):
"""
Return an HTML string with all help texts of all configured
validators,
separated by <br> tags.
"""
help_texts = password_validators_help_texts(password_validators)
return mark_safe("<br>".join(escape(h) for h in help_texts))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31158>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.7f37c9b80e43bd30ff36260ea0608816%40djangoproject.com.