Add aria-describedby to field help/error messages

This commit is contained in:
Joachim 2021-11-28 21:52:28 +01:00
parent 1fed22b27e
commit 403e282d88
4 changed files with 62 additions and 15 deletions

View file

@ -9,6 +9,7 @@ from django.utils import timezone
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from bookwyrm import models from bookwyrm import models
from bookwyrm.models.fields import ClearableFileInputWithWarning
class CustomForm(ModelForm): class CustomForm(ModelForm):
@ -147,6 +148,23 @@ class EditUserForm(CustomForm):
"preferred_language", "preferred_language",
] ]
help_texts = {f: None for f in fields} help_texts = {f: None for f in fields}
widgets = {
"avatar": ClearableFileInputWithWarning(
attrs={'aria-describedby': "desc_avatar"}
),
"name": forms.TextInput(
attrs={'aria-describedby': "desc_name"}
),
"summary": forms.Textarea(
attrs={'aria-describedby': "desc_summary"}
),
"email": forms.EmailInput(
attrs={'aria-describedby': "desc_email"}
),
"discoverable": forms.CheckboxInput(
attrs={'aria-describedby': "desc_discoverable"}
),
}
class LimitedEditUserForm(CustomForm): class LimitedEditUserForm(CustomForm):
@ -160,6 +178,20 @@ class LimitedEditUserForm(CustomForm):
"discoverable", "discoverable",
] ]
help_texts = {f: None for f in fields} help_texts = {f: None for f in fields}
widgets = {
"avatar": ClearableFileInputWithWarning(
attrs={'aria-describedby': "desc_avatar"}
),
"name": forms.TextInput(
attrs={'aria-describedby': "desc_name"}
),
"summary": forms.Textarea(
attrs={'aria-describedby': "desc_summary"}
),
"discoverable": forms.CheckboxInput(
attrs={'aria-describedby': "desc_discoverable"}
),
}
class DeleteUserForm(CustomForm): class DeleteUserForm(CustomForm):
@ -288,6 +320,17 @@ class SiteForm(CustomForm):
class Meta: class Meta:
model = models.SiteSettings model = models.SiteSettings
exclude = [] exclude = []
widgets = {
"instance_short_description": forms.TextInput(
attrs={'aria-describedby': "desc_instance_short_description"}
),
"require_confirm_email": forms.CheckboxInput(
attrs={'aria-describedby': "desc_require_confirm_email"}
),
"invite_request_text": forms.Textarea(
attrs={'aria-describedby': "desc_invite_request_text"}
),
}
class AnnouncementForm(CustomForm): class AnnouncementForm(CustomForm):

View file

@ -18,9 +18,9 @@
{% csrf_token %} {% csrf_token %}
<div class="field"> <div class="field">
<label class="label" for="id_password">{% trans "Confirm password:" %}</label> <label class="label" for="id_password">{% trans "Confirm password:" %}</label>
<input class="input {% if form.password.errors %}is-danger{% endif %}" type="password" name="password" id="id_password" required> <input class="input {% if form.password.errors %}is-danger{% endif %}" type="password" name="password" id="id_password" required aria-describedby="desc_password">
{% for error in form.password.errors %} {% for error in form.password.errors %}
<p class="help is-danger">{{ error | escape }}</p> <p class="help is-danger" id="desc_password">{{ error | escape }}</p>
{% endfor %} {% endfor %}
</div> </div>
<button type="submit" class="button is-danger">{% trans "Delete Account" %}</button> <button type="submit" class="button is-danger">{% trans "Delete Account" %}</button>

View file

@ -34,7 +34,7 @@
<div class="column"> <div class="column">
{{ form.avatar }} {{ form.avatar }}
{% for error in form.avatar.errors %} {% for error in form.avatar.errors %}
<p class="help is-danger">{{ error | escape }}</p> <p class="help is-danger" id="desc_avatar">{{ error | escape }}</p>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
@ -42,21 +42,21 @@
<label class="label" for="id_name">{% trans "Display name:" %}</label> <label class="label" for="id_name">{% trans "Display name:" %}</label>
{{ form.name }} {{ form.name }}
{% for error in form.name.errors %} {% for error in form.name.errors %}
<p class="help is-danger">{{ error | escape }}</p> <p class="help is-danger" id="desc_name">{{ error | escape }}</p>
{% endfor %} {% endfor %}
</div> </div>
<div class="field"> <div class="field">
<label class="label" for="id_summary">{% trans "Summary:" %}</label> <label class="label" for="id_summary">{% trans "Summary:" %}</label>
{{ form.summary }} {{ form.summary }}
{% for error in form.summary.errors %} {% for error in form.summary.errors %}
<p class="help is-danger">{{ error | escape }}</p> <p class="help is-danger" id="desc_summary">{{ error | escape }}</p>
{% endfor %} {% endfor %}
</div> </div>
<div class="field"> <div class="field">
<label class="label" for="id_email">{% trans "Email address:" %}</label> <label class="label" for="id_email">{% trans "Email address:" %}</label>
{{ form.email }} {{ form.email }}
{% for error in form.email.errors %} {% for error in form.email.errors %}
<p class="help is-danger">{{ error | escape }}</p> <p class="help is-danger" id="desc_email">{{ error | escape }}</p>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
@ -69,19 +69,23 @@
<div class="box"> <div class="box">
<div class="field"> <div class="field">
<label class="checkbox label" for="id_show_goal"> <label class="checkbox label" for="id_show_goal">
{% trans "Show reading goal prompt in feed:" %}
{{ form.show_goal }} {{ form.show_goal }}
{% trans "Show reading goal prompt in feed" %}
</label> </label>
</div>
<div class="field">
<label class="checkbox label" for="id_show_suggested_users"> <label class="checkbox label" for="id_show_suggested_users">
{% trans "Show suggested users:" %}
{{ form.show_suggested_users }} {{ form.show_suggested_users }}
{% trans "Show suggested users" %}
</label> </label>
</div>
<div class="field">
<label class="checkbox label" for="id_discoverable"> <label class="checkbox label" for="id_discoverable">
{% trans "Show this account in suggested users:" %}
{{ form.discoverable }} {{ form.discoverable }}
{% trans "Show this account in suggested users" %}
</label> </label>
{% url 'directory' as path %} {% url 'directory' as path %}
<p class="help"> <p class="help" id="desc_discoverable">
{% blocktrans %}Your account will show up in the <a href="{{ path }}">directory</a>, and may be recommended to other BookWyrm users.{% endblocktrans %} {% blocktrans %}Your account will show up in the <a href="{{ path }}">directory</a>, and may be recommended to other BookWyrm users.{% endblocktrans %}
</p> </p>
</div> </div>
@ -107,8 +111,8 @@
<div class="box"> <div class="box">
<div class="field"> <div class="field">
<label class="checkbox label" for="id_manually_approves_followers"> <label class="checkbox label" for="id_manually_approves_followers">
{% trans "Manually approve followers:" %}
{{ form.manually_approves_followers }} {{ form.manually_approves_followers }}
{% trans "Manually approve followers" %}
</label> </label>
</div> </div>
<div class="field"> <div class="field">

View file

@ -33,8 +33,8 @@
{{ site_form.instance_description }} {{ site_form.instance_description }}
</div> </div>
<div class="field"> <div class="field">
<label class="label mb-0" for="id_short_description">{% trans "Short description:" %}</label> <label class="label mb-0" for="id_instance_short_description">{% trans "Short description:" %}</label>
<p class="help">{% trans "Used when the instance is previewed on joinbookwyrm.com. Does not support HTML or Markdown." %}</p> <p class="help" id="desc_instance_short_description">{% trans "Used when the instance is previewed on joinbookwyrm.com. Does not support HTML or Markdown." %}</p>
{{ site_form.instance_short_description }} {{ site_form.instance_short_description }}
</div> </div>
<div class="field"> <div class="field">
@ -114,7 +114,7 @@
{{ site_form.require_confirm_email }} {{ site_form.require_confirm_email }}
{% trans "Require users to confirm email address" %} {% trans "Require users to confirm email address" %}
</label> </label>
<p class="help">{% trans "(Recommended if registration is open)" %}</p> <p class="help" id="desc_require_confirm_email">{% trans "(Recommended if registration is open)" %}</p>
</div> </div>
<div class="field"> <div class="field">
<label class="label" for="id_registration_closed_text">{% trans "Registration closed text:" %}</label> <label class="label" for="id_registration_closed_text">{% trans "Registration closed text:" %}</label>
@ -124,7 +124,7 @@
<label class="label" for="id_invite_request_text">{% trans "Invite request text:" %}</label> <label class="label" for="id_invite_request_text">{% trans "Invite request text:" %}</label>
{{ site_form.invite_request_text }} {{ site_form.invite_request_text }}
{% for error in site_form.invite_request_text.errors %} {% for error in site_form.invite_request_text.errors %}
<p class="help is-danger">{{ error|escape }}</p> <p class="help is-danger" id="desc_invite_request_text">{{ error|escape }}</p>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>