Opened 15 years ago

Closed 15 years ago

Last modified 12 years ago

#9587 closed (fixed)

formset with can_delete shouldn't require deleted forms to validate

Reported by: Daniel Pope <dan@…> 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)

formset_validation-r9699.diff (2.7 KB ) - added by Ivan Giuliani 15 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Ivan Giuliani, 15 years ago

Keywords: formset can_delete added

I see two possible solutions here:

  1. we don't validate the single form
  2. we validate the form, but the formset's will be valid even if the field that is going to be deleted is invalid

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 access form.cleaned_data since if the form has errors cleaned_data gets deleted).

by Ivan Giuliani, 15 years ago

comment:2 by Ivan Giuliani, 15 years ago

Has patch: set
Patch needs improvement: set

comment:3 by vbmendes, 15 years ago

Cc: vbmendes 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 Jacob, 15 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:5 by jkocherhans, 15 years ago

Resolution: fixed
Status: newclosed

(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 jkocherhans, 15 years ago

(In [10219]) [1.0.X] Fixed #9587. Formset.is_valid() now returns True if an invalid form is marked for deletion. Backport of r10206 from trunk.

comment:7 by jsamsa, 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 danstadler, 14 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.

comment:9 by Jacob, 12 years ago

milestone: 1.1

Milestone 1.1 deleted

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