Can someone tell me if a form in an inlineformset should go through validation if the DELETE field is checked. I have a form that uses an inlineformset and when I check the DELETE box it fails because the required fields are blank. If I put data in the fields it will pass validation and then be deleted.
Is that how it is supposed to work, I would have thought that if it is marked for delete it would bypass the validation for that form.
Follow up - but I would still appreciate some others opinions/help
The way I have gotten around this by adding in a check in the add_fields that tests if the DELETE input is True and if it is it makes all fields on the form not required, which means it passes validation and will then delete.
def add_fields(self, form, index) #add other fields that are required.... deleteValue = form.fields['DELETE'].widget.value_from datadict(form.data, form.files, form.add_prefix('DELETE')) if bool(deleteValue) or deleteValue == '': for name, field in form.fields.items(): form.fields[name].required= False
This seems to be an odd way to do things but I cannot figure out another way. Is there a simpler way that I am missing?
I have also noticed that when I add the new form to my page and check the Delete box, there is no value passed back via the request, however an existing form (one loaded from the database) has a value of
on when the Delete box is checked. If the box is not checked then the input is not in the request at all.
© Stack Overflow or respective owner