Opened 21 months ago

Closed 20 months ago

Last modified 9 months ago

#34488 closed Cleanup/optimization (fixed)

ClearableFileInput widget forgets "Clear" selection when form is not valid

Reported by: bmihelac Owned by: Marcelo Galigniana
Component: Forms Version: 4.1
Severity: Normal Keywords: admin, forms, ClearableFileInput
Cc: Marcelo Galigniana Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by bmihelac)

ClearableFileInput widget forgets "Clear" selection when form is not valid, that causes file would not be deleted once when form is valid again. This can be inconvinient, especially for forms with many fields.

To reproduce:

  1. Choose admin for any model instance where attachment is not required and has some validation,
  2. check "Clear" next to the attachment, and change the form, so validation would fail,
  3. Save form, validation error would occur, attachment and "Clear" would be empty
  4. make form valid again and Save, attachment woult not be cleared

(I am attaching example screenshots)

https://code.djangoproject.com/attachment/ticket/34488/clearable-file-input-before.png

https://code.djangoproject.com/attachment/ticket/34488/clearable-file-input-validation-error.png

https://code.djangoproject.com/attachment/ticket/34488/clearable-file-input-validation-success.png

Attachments (7)

clearable-file-input-before.png (36.9 KB ) - added by bmihelac 21 months ago.
initial state
clearable-file-input-validation-error.2.png (32.8 KB ) - added by bmihelac 21 months ago.
clearable-file-input-validation-error.png (32.8 KB ) - added by bmihelac 21 months ago.
validation error occurs (ClearableFileInput has no file and has no Clear checkbox)
clearable-file-input-validation-success.png (36.4 KB ) - added by bmihelac 21 months ago.
File is not removed after successful validation and saving
django41-c.webm (86.2 KB ) - added by bmihelac 21 months ago.
django42-c.webm (114.5 KB ) - added by bmihelac 21 months ago.
ticket_34488_mgaligniana.jpeg (87.9 KB ) - added by Marcelo Galigniana 20 months ago.
When do a submit and validation error occurs, we persist the "invalid" data in the form. I think keep the checkbox checked would be the same behaviour.

Download all attachments as: .zip

Change History (22)

comment:1 by bmihelac, 21 months ago

Description: modified (diff)

comment:2 by bmihelac, 21 months ago

Description: modified (diff)

by bmihelac, 21 months ago

initial state

by bmihelac, 21 months ago

validation error occurs (ClearableFileInput has no file and has no Clear checkbox)

by bmihelac, 21 months ago

File is not removed after successful validation and saving

comment:3 by Baha Sdtbekov, 21 months ago

Owner: changed from nobody to Baha Sdtbekov
Status: newassigned

comment:4 by Baha Sdtbekov, 21 months ago

Hello, could you please share your models, forms and admin?
Because everything works fine for me.

comment:5 by Mariusz Felisiak, 21 months ago

Resolution: duplicate
Status: assignedclosed

Duplicate of #19215 (fixed in c0fc1b5302f5d9d82e2255fb5758321fbac34949, Django 4.2+).

by bmihelac, 21 months ago

Attachment: django41-c.webm added

by bmihelac, 21 months ago

Attachment: django42-c.webm added

comment:6 by bmihelac, 21 months ago

Hi Basha,

I have created minimum app

https://github.com/bmihelac/django-34488

credentials are admin:test

Please note that app behaves differently in Django 4.1.x and Django 4.2.x (as you can see on screencast below or try yourself). Django 4.2 still forget clear checkbox, but at least checkbox is shown.

https://code.djangoproject.com/attachment/ticket/34488/django41-c.webm
https://code.djangoproject.com/attachment/ticket/34488/django42-c.webm

let me know if anything else is needed

in reply to:  5 ; comment:7 by bmihelac, 21 months ago

Replying to Mariusz Felisiak:

Duplicate of #19215 (fixed in c0fc1b5302f5d9d82e2255fb5758321fbac34949, Django 4.2+).

It still forgot Clear choice on validation error in Django 4.2 (this is visible in https://code.djangoproject.com/attachment/ticket/34488/django42-c.webm screencast)

in reply to:  7 comment:8 by Mariusz Felisiak, 21 months ago

Cc: Marcelo Galigniana added

Replying to bmihelac:

Replying to Mariusz Felisiak:

Duplicate of #19215 (fixed in c0fc1b5302f5d9d82e2255fb5758321fbac34949, Django 4.2+).

It still forgot Clear choice on validation error in Django 4.2 (this is visible in https://code.djangoproject.com/attachment/ticket/34488/django42-c.webm screencast)

"Clear" is always unchecked, I'm not sure if we should change this. Marcelo, what do you think?

by Marcelo Galigniana, 20 months ago

When do a submit and validation error occurs, we persist the "invalid" data in the form. I think keep the checkbox checked would be the same behaviour.

comment:9 by Mariusz Felisiak, 20 months ago

Resolution: duplicate
Status: closednew
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

When do a submit and validation error occurs, we persist the "invalid" data in the form. I think keep the checkbox checked would be the same behaviour.

Agreed. Would you like to prepare a patch?

comment:10 by Marcelo Galigniana, 20 months ago

Owner: changed from Baha Sdtbekov to Marcelo Galigniana
Status: newassigned

Sure!

I see Baha Sdtbekov took the owner 4 days ago. I'm going to assign it to me but in case you already been working on it, please let me know!

Thanks!

Last edited 20 months ago by Marcelo Galigniana (previous) (diff)

comment:11 by Mariusz Felisiak, 20 months ago

Has patch: set
Patch needs improvement: set

comment:12 by Marcelo Galigniana, 20 months ago

Patch needs improvement: unset

comment:13 by Mariusz Felisiak, 20 months ago

Triage Stage: AcceptedReady for checkin

comment:14 by Mariusz Felisiak <felisiak.mariusz@…>, 20 months ago

Resolution: fixed
Status: assignedclosed

In 8a6c0203:

Fixed #34488 -- Made ClearableFileInput preserve "Clear" checked attribute when form is invalid.

comment:15 by Mariusz Felisiak <felisiak.mariusz@…>, 9 months ago

In 3d7235c:

Refs #34488 -- Made ClearableFileInput preserve "Clear" checked attribute when form is invalid.

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