Opened 5 years ago

Closed 4 years ago

Last modified 2 years ago

#31536 closed Bug (fixed)

Disabled clearable file field widget is not disabling the checkbox

Reported by: Carles Pina Estany Owned by: Carles Pina Estany
Component: Forms Version: dev
Severity: Normal Keywords: form, filefield, clearable_file_input
Cc: David Smith Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: yes

Description

Using a forms.FileField with a disabled widget is disabling the "Browse" button but not the checkbox to "Clear" the file.

Checking the checkbox and submitting cause no effect since the widget is disabled but the UI is confusing.

Attachments (1)

31536-clearable_file_input_disabled.patch (2.9 KB ) - added by Carles Pina Estany 5 years ago.
Possible patch for the described problem

Download all attachments as: .zip

Change History (13)

by Carles Pina Estany, 5 years ago

Possible patch for the described problem

comment:1 by Carles Pina Estany, 5 years ago

Possible fix: https://github.com/cpina/django/tree/ticket_31536 (or attached as a patch)

Let me know if I can do anything else - if a unit test needs to be improved or added I can have a look, I'm new here and I haven't looked yet if templates have accompanying unit tests but I thought of sending the patch for now.

comment:2 by Carles Pina Estany, 5 years ago

If the fix looked good I'm happy to re-write the commit message to past tense and with "fixed"

comment:3 by Carlton Gibson, 5 years ago

Easy pickings: set
Needs tests: set
Triage Stage: UnreviewedAccepted

Hi Carles, seems reasonable yes.

Please assign yourself this issue, open a PR on GitHub, and do include some tests too. :)

There are related tests here: django/tests/forms_tests/widget_tests/test_clearablefileinput.py

Thanks!

comment:4 by Carles Pina Estany, 5 years ago

Owner: changed from nobody to Carles Pina Estany
Status: newassigned

comment:5 by David Smith, 5 years ago

Cc: David Smith added

in reply to:  3 comment:6 by Carles Pina Estany, 5 years ago

Hi Carlton,

Replying to Carlton Gibson:

Hi Carles, seems reasonable yes.

Please assign yourself this issue, open a PR on GitHub, and do include some tests too. :)

Done here:
https://github.com/django/django/pull/12864

There are related tests here: django/tests/forms_tests/widget_tests/test_clearablefileinput.py

Thanks for the pointer, done the test there as well (it also tests the "disabled" on the input field)

Cheers,

comment:7 by Carles Pina Estany, 5 years ago

Needs tests: unset

Unticked "Needs tests": tests are now in the PR

comment:8 by Carles Pina Estany, 5 years ago

Adding PR link to find it easier: https://github.com/django/django/pull/12864

Thanks,

comment:9 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin
Type: Cleanup/optimizationBug

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In e46c2326:

Fixed #31536 -- Fixed rendering of disabled AdminFileWidget and ClearableFileInput.

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 56af541:

[3.1.x] Fixed #31536 -- Fixed rendering of disabled AdminFileWidget and ClearableFileInput.

Backport of e46c2326c8cfc038e015f55fd050ab5d7eb91b62 from master

comment:12 by Horst Schneider, 2 years ago

It seems like the fix to this issue raised a problem similar to Ticket #32681: Not checking whether the disabled attribute actually exists on the attrs of the 'clear' checkbox causes a VariableDoesNotExist exception to be logged every time the template is rendered with a checkbox that has no disabled atrribute:

[2022-07-06 10:06:03,452] DEBUG django.template base: Exception while resolving variable 'disabled' in template 'admin/widgets/clearable_file_input.html'.
Traceback (most recent call last):
  File "/home/horst/some_project/venv/lib/python3.10/site-packages/django/template/base.py", line 875, in _resolve_lookup
    current = current[bit]
KeyError: 'disabled'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/horst/some_project/venv/lib/python3.10/site-packages/django/template/base.py", line 885, in _resolve_lookup
    current = getattr(current, bit)
AttributeError: 'dict' object has no attribute 'disabled'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/horst/some_project/venv/lib/python3.10/site-packages/django/template/base.py", line 891, in _resolve_lookup
    current = current[int(bit)]
ValueError: invalid literal for int() with base 10: 'disabled'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/horst/some_project/venv/lib/python3.10/site-packages/django/template/base.py", line 898, in _resolve_lookup
    raise VariableDoesNotExist(
django.template.base.VariableDoesNotExist: Failed lookup for key [disabled] in {'id': 'id_document'}

Should this be a new ticket?

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