#9587 closed (fixed)
formset with can_delete shouldn't require deleted forms to validate
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Forms | Version: | 1.0 |
Severity: | Keywords: | formset can_delete | |
Cc: | vbmendes | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
If I check the can_delete checkbox for a FormSet form, I would expect the form to be deleted regardless of whether there are validation errors in that particular form. I'm getting "This field is required" even for forms I'm trying to delete.
I'm using inlineformset_factory.
Attachments (1)
Change History (10)
comment:1 by , 16 years ago
Keywords: | formset can_delete added |
---|
by , 16 years ago
Attachment: | formset_validation-r9699.diff added |
---|
comment:2 by , 16 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
comment:3 by , 16 years ago
Cc: | added |
---|
I think the first solution is better. If you want to delete the form, it doesn't matter if it validates or not.
comment:4 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:5 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In [10206]) Fixed #9587. Formset.is_valid() now returns True if an invalid form is marked for deletion. Thanks for the test and intial patch, kratorius.
Note that this leaves the form and formset errors alone. Those forms still have errors, it's just that it doesn't matter that they're invalid in the context of the formset and deletion.
Also fixed #9665 while I was in there. Thanks, mark_hildreth.
comment:6 by , 16 years ago
comment:7 by , 15 years ago
Can we improve this to read the delete field value from cleaned_data so that validation has a chance to raise validation errors on delete? I have a case where I don't want to allow delete on inlines after the parent model reaches a certain state. I'll try writing a patch.
comment:8 by , 15 years ago
I would agree with jsamsa's comment on 06/08/09. I have a case where I don't want to delete the last child object, if the parent object is in a particular state. I'd like to be able to throw a ValidationError on delete, but that doesn't seem allowed. BTW we are on Django 1.0.3.
I see two possible solutions here:
I'm more inclined to go with the second option since if the user checks the deletion checkbox but other fields are invalid, we should redisplay the whole formset and show eventual errors.
Anyway I can't see a clean way of fixing this issue. I wrote a patch, but I don't like the solution mainly because the only way I have to know if the form has to be deleted is to check for the
DELETE
string in the initial data (I can't accessform.cleaned_data
since if the form has errorscleaned_data
gets deleted).