#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)
Change History (13)
by , 5 years ago
Attachment: | 31536-clearable_file_input_disabled.patch added |
---|
comment:1 by , 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 , 5 years ago
If the fix looked good I'm happy to re-write the commit message to past tense and with "fixed"
follow-up: 6 comment:3 by , 5 years ago
Easy pickings: | set |
---|---|
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
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 , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 5 years ago
Cc: | added |
---|
comment:6 by , 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:8 by , 5 years ago
Adding PR link to find it easier: https://github.com/django/django/pull/12864
Thanks,
comment:9 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|---|
Type: | Cleanup/optimization → Bug |
comment:12 by , 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?
Possible patch for the described problem