views:

58

answers:

1

I have a from based on ModelForm and use formset_factory to create a formset based on two dictionaries. There is also one extra form.

In my view, I use the formset JS plugin and I delete the two forms with data. When I POST the remaining empty extra form, it fails validation because of a required field.

I don't understand why that form is being validated. Its changed_data list is empty. It is returned with empty_permitted = False (and I'd like to know why that is), but even after I change it to True in the debugger, it is validated.

So what is triggering validation and how can I modify it?

I would also be interested to know where data like the initial data is stored. Is that somewhere in my view where I am not seeing it?

A: 

The template management form has a counter called INITIAL_FORMS. The formset plugin for adding and deleting forms does not distinguish between initially populated forms and forms it adds. When a form is deleted, if it was initially populated, then INITIAL_FORMS should be decremented.

This can be implemented by including a template variable which flags forms which are initially populated. In the removed function of the formset plugin, if one of these flagged forms is being deleted, then decrement INITIAL_FORMS.

Mitch