Opened 3 years ago

Closed 3 years ago

Last modified 15 months 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 3 years ago.
Possible patch for the described problem

Download all attachments as: .zip

Change History (13)

Changed 3 years ago by Carles Pina Estany

Possible patch for the described problem

comment:1 Changed 3 years ago by Carles Pina Estany

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 Changed 3 years ago by Carles Pina Estany

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

comment:3 Changed 3 years ago by Carlton Gibson

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 Changed 3 years ago by Carles Pina Estany

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

comment:5 Changed 3 years ago by David Smith

Cc: David Smith added

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

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 Changed 3 years ago by Carles Pina Estany

Needs tests: unset

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

comment:8 Changed 3 years ago by Carles Pina Estany

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

Thanks,

comment:9 Changed 3 years ago by Mariusz Felisiak

Triage Stage: AcceptedReady for checkin
Type: Cleanup/optimizationBug

comment:10 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In e46c2326:

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

comment:11 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

In 56af541:

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

Backport of e46c2326c8cfc038e015f55fd050ab5d7eb91b62 from master

comment:12 Changed 15 months ago by Horst Schneider

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