Django FormWizard with dynamic forms

后端 未结 5 1906
既然无缘
既然无缘 2021-02-04 18:48

I want to implement a simple 2 part FormWizard. Form 1 will by dynamically generated something like this:

class BuyAppleForm(forms.Form):
   creditcard = forms.C         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 19:36

    Thank you krys for answering to your own question. Helped me, but I still got some remarks.

    FormPreview is not the way to go since it as far as I know does not support dynamic forms. It relies on a fixed form class to generate the from from there. But we are generating dynamically here with a function. Maybe FormPreview will support this one day (or already does and I dont know how).

    Krys solution seems to do the same as FormPreview. Only the hash is left out, so user may change data in the hidden fields or do you check it again?. If you check it again, that would not be following DRY because you duplicate the check (okay, could be in a reusable method, so only tiny repetition).

    What I was wondering, how do you adjust the widget? Do you duplicate the form with the new widgets or is there a way to change that dynamically?

提交回复
热议问题