views:

25

answers:

1

formset.empty_form is great for generating a blank form that I can use in my JS. However, once the form has been posted, empty_form suddenly contains error messages and it magically forgets all its initial values. Why is that?

Instead, I have to do this stupid hack to get an actually empty form

empty_form = MyFormSet().empty_form

Regardless if there is post data. I can't even just overwrite it with

myformset.empty_form = MyFormSet().empty_form

Because it throws this stupid error message

can't set attribute

A: 

It seems to me that, formset.empty_form intended to serve the extra empty forms required to be displayed as per the parameter extra=n passed to the formset, and doesn't serve your purpose to display as many empty forms in those places.

The new forms generated need to have an id similar and incremental to the one that would be in progression of the forms. Without the actual formset data and the count of the number of forms, how would .empty_form know the respective id.

Lakshman Prasad
Actually, my purpose is precisely what its intended for: http://docs.djangoproject.com/en/dev/topics/forms/formsets/#empty-form It leaves `__prefix__` in place of the ID so that you can easily find-and-replace it with the appropriate ID.
Mark