开发者

Why does formset.empty_form contain errors and forget initial values?

开发者 https://www.devze.com 2023-01-11 04:10 出处:网络
f开发者_运维技巧ormset.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 for

f开发者_运维技巧ormset.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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消