Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-mm committed Nov 16, 2023
2 parents 234d548 + 292f1ea commit bec8dde
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 19 deletions.
5 changes: 3 additions & 2 deletions django/forms/boundfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,10 @@ def build_widget_attrs(self, attrs, widget=None):
not attrs.get("aria-describedby")
and not widget.attrs.get("aria-describedby")
and self.field.help_text
and self.id_for_label
and not self.use_fieldset
and self.auto_id
):
attrs["aria-describedby"] = f"{self.id_for_label}_helptext"
attrs["aria-describedby"] = f"{self.auto_id}_helptext"
return attrs

@property
Expand Down
2 changes: 1 addition & 1 deletion django/forms/jinja2/django/forms/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% else %}
{% if field.label %}{{ field.label_tag() }}{% endif %}
{% endif %}
{% if field.help_text %}<div class="helptext"{% if field.id_for_label %} id="{{ field.id_for_label}}_helptext"{% endif %}>{{ field.help_text|safe }}</div>{% endif %}
{% if field.help_text %}<div class="helptext"{% if field.auto_id %} id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</div>{% endif %}
{{ field.errors }}
{{ field }}
{% if field.use_fieldset %}</fieldset>{% endif %}
2 changes: 1 addition & 1 deletion django/forms/jinja2/django/forms/p.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% if field.label %}{{ field.label_tag() }}{% endif %}
{{ field }}
{% if field.help_text %}
<span class="helptext"{% if field.id_for_label %} id="{{ field.id_for_label}}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
<span class="helptext"{% if field.auto_id %} id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
{% endif %}
{% if loop.last %}
{% for field in hidden_fields %}{{ field }}{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion django/forms/jinja2/django/forms/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{ field }}
{% if field.help_text %}
<br>
<span class="helptext"{% if field.id_for_label %} id="{{ field.id_for_label}}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
<span class="helptext"{% if field.auto_id %} id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
{% endif %}
{% if loop.last %}
{% for field in hidden_fields %}{{ field }}{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion django/forms/jinja2/django/forms/ul.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% if field.label %}{{ field.label_tag() }}{% endif %}
{{ field }}
{% if field.help_text %}
<span class="helptext"{% if field.id_for_label %} id="{{ field.id_for_label}}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
<span class="helptext"{% if field.auto_id %} id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
{% endif %}
{% if loop.last %}
{% for field in hidden_fields %}{{ field }}{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion django/forms/templates/django/forms/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% else %}
{% if field.label %}{{ field.label_tag }}{% endif %}
{% endif %}
{% if field.help_text %}<div class="helptext"{% if field.id_for_label %} id="{{ field.id_for_label}}_helptext"{% endif %}>{{ field.help_text|safe }}</div>{% endif %}
{% if field.help_text %}<div class="helptext"{% if field.auto_id %} id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</div>{% endif %}
{{ field.errors }}
{{ field }}
{% if field.use_fieldset %}</fieldset>{% endif %}
2 changes: 1 addition & 1 deletion django/forms/templates/django/forms/p.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% if field.label %}{{ field.label_tag }}{% endif %}
{{ field }}
{% if field.help_text %}
<span class="helptext"{% if field.id_for_label %} id="{{ field.id_for_label}}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
<span class="helptext"{% if field.auto_id %} id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
{% endif %}
{% if forloop.last %}
{% for field in hidden_fields %}{{ field }}{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion django/forms/templates/django/forms/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{ field }}
{% if field.help_text %}
<br>
<span class="helptext"{% if field.id_for_label %} id="{{ field.id_for_label}}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
<span class="helptext"{% if field.auto_id %} id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
{% endif %}
{% if forloop.last %}
{% for field in hidden_fields %}{{ field }}{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion django/forms/templates/django/forms/ul.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% if field.label %}{{ field.label_tag }}{% endif %}
{{ field }}
{% if field.help_text %}
<span class="helptext"{% if field.id_for_label %} id="{{ field.id_for_label}}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
<span class="helptext"{% if field.auto_id %} id="{{ field.auto_id }}_helptext"{% endif %}>{{ field.help_text|safe }}</span>
{% endif %}
{% if forloop.last %}
{% for field in hidden_fields %}{{ field }}{% endfor %}
Expand Down
6 changes: 3 additions & 3 deletions docs/ref/forms/fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ fields. We've specified ``auto_id=False`` to simplify the output:
<div>Sender:<div class="helptext">A valid email address, please.</div><input type="email" name="sender" required></div>
<div>Cc myself:<input type="checkbox" name="cc_myself"></div>

When a field has help text and :attr:`~django.forms.BoundField.id_for_label`
returns a value, we associate ``help_text`` with the input using the
``aria-describedby`` HTML attribute:
When a field has help text and the widget is not rendered in a ``<fieldset>``,
``aria-describedby`` is added to the ``<input>`` to associate it to the
help text:

.. code-block:: pycon

Expand Down
6 changes: 3 additions & 3 deletions docs/releases/5.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ For example, the template below:
<div>
{{ form.name.label_tag }}
{% if form.name.help_text %}
<div class="helptext" id="{{ form.name.id_for_label }}_helptext">
<div class="helptext" id="{{ form.name.auto_id }}_helptext">
{{ form.name.help_text|safe }}
</div>
{% endif %}
Expand All @@ -71,7 +71,7 @@ For example, the template below:
<div class="col">
{{ form.email.label_tag }}
{% if form.email.help_text %}
<div class="helptext" id="{{ form.email.id_for_label }}_helptext">
<div class="helptext" id="{{ form.email.auto_id }}_helptext">
{{ form.email.help_text|safe }}
</div>
{% endif %}
Expand All @@ -81,7 +81,7 @@ For example, the template below:
<div class="col">
{{ form.password.label_tag }}
{% if form.password.help_text %}
<div class="helptext" id="{{ form.password.id_for_label }}_helptext">
<div class="helptext" id="{{ form.password.auto_id }}_helptext">
{{ form.password.help_text|safe }}
</div>
{% endif %}
Expand Down
5 changes: 3 additions & 2 deletions docs/topics/auth/passwords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,9 @@ can write your own as well.

Each password validator must provide a help text to explain the requirements to
the user, validate a given password and return an error message if it does not
meet the requirements, and optionally receive passwords that have been set.
Validators can also have optional settings to fine tune their behavior.
meet the requirements, and optionally define a callback to be notified when
the password for a user has been changed. Validators can also have optional
settings to fine tune their behavior.

Validation is controlled by the :setting:`AUTH_PASSWORD_VALIDATORS` setting.
The default for the setting is an empty list, which means no validators are
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/forms/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ loop:
{{ field.errors }}
{{ field.label_tag }} {{ field }}
{% if field.help_text %}
<p class="help" id="{{ field.id_for_label }}_helptext">
<p class="help" id="{{ field.auto_id }}_helptext">
{{ field.help_text|safe }}
</p>
{% endif %}
Expand Down

0 comments on commit bec8dde

Please sign in to comment.