#30833 closed Cleanup/optimization (invalid)
Use field label when available to display errors in forms.
| Reported by: | Lorran Rosa | Owned by: | Lorran Rosa |
|---|---|---|---|
| Component: | Forms | Version: | 3.0 |
| Severity: | Normal | Keywords: | forms, label, internationalization |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
The issue here is if you have a form field called "year" even if you set a label like "Ano" form.errors will display "year".
Which can be confusing for non-english speakers.
Attachments (1)
Change History (8)
comment:1 by , 6 years ago
| Has patch: | unset |
|---|---|
| Resolution: | → needsinfo |
| Status: | assigned → closed |
| Summary: | Use field label when available to display errors in forms → Use field label when available to display errors in forms. |
| UI/UX: | unset |
| Version: | 2.2 → 3.0 |
comment:2 by , 6 years ago
| Resolution: | needsinfo |
|---|---|
| Status: | closed → new |
| UI/UX: | set |
Lets supose I have a form like this:
class WritersForm(forms.Form):
name = forms.CharField(label='Your name', max_length=45)
number = forms.IntegerField(
widget=forms.TextInput(),
label='Número'
)
I still want to validade number field but I don't like de IntergerField widget style so I use TextInput widget instead.
My template is like this:
{{ form.errors }}
<form action='{% url "create_writer" %}' method="POST">
{% csrf_token %}
<div class="form-group">
{{ form.name.label_tag }}
{{ form.name }}
{{ form.number.label_tag }}
{{ form.number }}
</div>
<input type="submit" class="btn bg-primary" value="Submit">
</form>
if I do not input a Interger in "number" field my form.errors returns:
number
Enter a whole number.
Even with the field "label" argument defined in forms to "Número".
The desired behavior would be errors to use label field when available:
Número
Enter a whole number.
comment:3 by , 6 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
"Enter a whole number" is a translated message (for users) and number is a key in a dictionary with errors that maps fields to their errors. This is expected behavior (see documentation).
Please use one of support channels.
comment:4 by , 6 years ago
| Resolution: | invalid |
|---|---|
| Status: | closed → new |
Got your point. But in not so simple forms as the one above it can be really confusing, let me elaborate:
class WritersForm(forms.Form):
name = forms.CharField(label='имя', max_length=45)
number = forms.IntegerField(
widget=forms.TextInput(),
label='номер'
),
year = forms.IntegerField(
widget=forms.TextInput(),
label='год'
),
house_number = forms.IntegerField(
widget=forms.TextInput(),
label=Номер дома'
),
If my russian user mistyped something he/she will see this:
number
Пожалуйста, введите правильный номер.
house_number
Пожалуйста, введите правильный номер.
"year" also expects a "number" as input, if my user do not speak english how do it know which field was mistyped ?
What is seen in form is "номер", "год", "Номер дома".
comment:5 by , 6 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
You can display errors related with fields directly with them
{{ form.number.errors.as_ul }}
Please don't reopen closed ticket and use support channels for support questions.
comment:6 by , 6 years ago
| Resolution: | invalid → worksforme |
|---|
Thanks for your time, It isn't the behavior I expected but meet my needs.
comment:7 by , 6 years ago
| Resolution: | worksforme → invalid |
|---|---|
| UI/UX: | unset |
Ticket is "invalid" because it was a support question not an issue in Django (see documentation).
Thanks for this report, however I cannot find any builtin validator with message that contains field's name. Can you provide more details?