Opened 3 weeks ago

Last modified 2 weeks ago

#36828 assigned Cleanup/optimization

Evaluate using <fieldset> on ClearableFileInput

Reported by: Johannes Maron Owned by: Youngkwang Yang
Component: Forms Version: 6.0
Severity: Normal Keywords: accessibility, label, wcag, fieldset
Cc: Johannes Maron, Antoliny Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Johannes Maron)

Howdy,

I noticed Django sometimes replaces the label with a fieldset tag. However, input labels are required as of WCAG 2.1; see also: https://www.w3.org/TR/WCAG21/#labels-or-instructions

Since Django must be WCAG2.2 AAA compliant, we might even want to patch all supported versions. However, this would mean shipping a rendering change in a bugfix.

My current impulse would be to enforce labels for WCAG compliance in 6.1, since shipping a rendering change within a bug fix release might result into more issues for users.

Cheers!
Joe

Change History (14)

comment:1 by Johannes Maron, 3 weeks ago

Keywords: accessibility added

comment:2 by Johannes Maron, 3 weeks ago

Description: modified (diff)

comment:3 by Youngkwang Yang, 3 weeks ago

Owner: set to Youngkwang Yang
Status: newassigned

comment:4 by Youngkwang Yang, 3 weeks ago

This looks similar to #36724 (fixed in PR https://github.com/django/django/pull/20080).
could you check which version you're testing with?

comment:5 by Johannes Maron, 3 weeks ago

Thanks! Yes, that does resolve half of the issue. We have correct HTML, but the WCAG violation remains.

comment:6 by Johannes Maron, 3 weeks ago

Description: modified (diff)

comment:7 by Johannes Maron, 3 weeks ago

Summary: Django form fields render into invalid HTMLMissing input labels (WCAG2.1)

comment:8 by Antoliny, 3 weeks ago

Thank you, Joe :)

Could you share an example of where the issue shows up?

My guess is that you’re referring to ClearableFileInput, which was recently switched to use a fieldset. When using the ClearableFileInput widget and an initial value is present, it appears that the input for changing the value does not have an associated label.

Since the original label was replaced by a legend, it seems that this part (the “changed” input) should now have an associated label.

Is this the case you had in mind?

Last edited 3 weeks ago by Antoliny (previous) (diff)

comment:9 by Antoliny, 3 weeks ago

Cc: Antoliny added

comment:10 by Jacob Walls, 3 weeks ago

Keywords: label wcag fieldset added
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Version: dev6.0

Accepting as a 6.0 regression on the basis that when use_fieldset = True was used on ClearableFileInput in #35892, we didn't audit its template for the presence of a <label>. radio_option.html had a label, but clearable_file_input.html didn't.

Since the original label was replaced by a legend, it seems that this part (the “changed” input) should now have an associated label.

I agree -- thanks for the triage!!

When using the ClearableFileInput widget and an initial value is present, it appears that the input for changing the value does not have an associated label.

I don't think it depends on the initial value, see:

from django.db import models
from django import forms

class Upload(models.Model):
    file = models.FileField(
        verbose_name="CSV-File",
        upload_to="csv",
        help_text="File containing comma separated values.",
    )
    class Meta:
        app_label = "myapp.Upload"

class UploadForm(forms.ModelForm):
    class Meta:
        model = Upload
        fields = ["file"]

print(UploadForm().as_div())

5.2.9, with <label>:

<div>
    <label for="id_file">CSV-File:</label>

<div class="helptext" id="id_file_helptext">File containing comma separated values.</div>

<input type="file" name="file" required aria-describedby="id_file_helptext" id="id_file">
    
      
    
</div>

6.0, without:

<div>
    <fieldset aria-describedby="id_file_helptext">
  <legend for="id_file">CSV-File:</legend>

<div class="helptext" id="id_file_helptext">File containing comma separated values.</div>

<input type="file" name="file" required id="id_file"></fieldset>
    
      
    
</div>

We should target a fix for 6.0.1 on January 6.

comment:11 by Jacob Walls, 3 weeks ago

Summary: Missing input labels (WCAG2.1)Missing input label (WCAG2.1) on ClearableFileInput

comment:12 by Jacob Walls, 2 weeks ago

Severity: Release blockerNormal
Summary: Missing input label (WCAG2.1) on ClearableFileInputEvaluate using <fieldset> on ClearableFileInput

No longer a release blocker given #36829 will revert the underlying change here in 6.0.1.

Re-framing as a new cleanup ticket as suggested in ticket:36829#comment:9 to explore using <fieldset> on ClearableFileInput:

  • confirming that we want to do so
  • changing the default template to have labels
  • deciding if the use of fieldset should be conditional somehow
  • evaluating whether a deprecation path is needed
Last edited 2 weeks ago by Jacob Walls (previous) (diff)

comment:13 by Jacob Walls, 2 weeks ago

Type: BugCleanup/optimization

comment:14 by Jacob Walls, 2 weeks ago

See ticket:32339#comment:2 for ideation around a deprecation path for widget rendering changes.

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