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)
--
Ticket URL: <https://code.djangoproject.com/ticket/34488>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "clearable-file-input-before.png" added.
initial state
* Attachment "clearable-file-input-validation-error.png" added.
validation error occurs (ClearableFileInput has no file and has no Clear
checkbox)
* Attachment "clearable-file-input-validation-success.png" added.
File is not removed after successful validation and saving
Old description:
> 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)
New description:
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)
[[Image(https://code.djangoproject.com/attachment/ticket/34488/clearable-
file-input-before.png)]]
[[Image(https://code.djangoproject.com/attachment/ticket/34488/clearable-
file-input-validation-error.png)]]
[[Image(https://code.djangoproject.com/attachment/ticket/34488/clearable-
file-input-validation-success.png)]]
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:1>
Old description:
> [[Image(https://code.djangoproject.com/attachment/ticket/34488/clearable-
> file-input-before.png)]]
>
> [[Image(https://code.djangoproject.com/attachment/ticket/34488/clearable-
> file-input-validation-error.png)]]
>
> [[Image(https://code.djangoproject.com/attachment/ticket/34488/clearable-
> file-input-validation-success.png)]]
New description:
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]]
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:2>
* Attachment "clearable-file-input-before.png" added.
initial state
--
Ticket URL: <https://code.djangoproject.com/ticket/34488>
* Attachment "clearable-file-input-before.png" removed.
* Attachment "clearable-file-input-validation-error.2.png" added.
* Attachment "clearable-file-input-validation-error.png" added.
validation error occurs (ClearableFileInput has no file and has no Clear
checkbox)
--
* Attachment "clearable-file-input-validation-error.png" removed.
* Attachment "clearable-file-input-validation-success.png" removed.
File is not removed after successful validation and saving
--
* Attachment "clearable-file-input-validation-success.png" added.
* owner: nobody => Bakdolot
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:3>
Comment (by Baha Sdtbekov):
Hello, could you please share your models, forms and admin?
Because everything works fine for me.
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:4>
* status: assigned => closed
* resolution: => duplicate
Comment:
Duplicate of #19215 (fixed in c0fc1b5302f5d9d82e2255fb5758321fbac34949,
Django 4.2+).
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:5>
* Attachment "django41-c.webm" added.
--
Ticket URL: <https://code.djangoproject.com/ticket/34488>
* Attachment "django42-c.webm" added.
Comment (by bmihelac):
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
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:6>
Comment (by bmihelac):
Replying to [comment:5 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)
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:7>
* cc: Marcelo Galigniana (added)
Comment:
Replying to [comment:7 bmihelac]:
> Replying to [comment:5 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?
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:8>
* Attachment "ticket_34488_mgaligniana.jpeg" added.
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/34488>
* status: closed => new
* type: Bug => Cleanup/optimization
* resolution: duplicate =>
* stage: Unreviewed => Accepted
Comment:
> 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?
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:9>
* owner: Baha Sdtbekov => Marcelo Galigniana
* status: new => assigned
Comment:
Sure!
I see Baha Sdtbekov took the owner 4 days ago. I'm going to assign it to
me but in case you were been working on it, please let me know!
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:10>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/16785 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:11>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:12>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:13>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"8a6c0203c4e92908c2b26ba54feba4ce7e76d081" 8a6c0203]:
{{{
#!CommitTicketReference repository=""
revision="8a6c0203c4e92908c2b26ba54feba4ce7e76d081"
Fixed #34488 -- Made ClearableFileInput preserve "Clear" checked attribute
when form is invalid.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34488#comment:14>