Dynamically adding a form to a Django formset with Ajax

后端 未结 15 1896
不思量自难忘°
不思量自难忘° 2020-11-22 03:09

I want to automatically add new forms to a Django formset using Ajax, so that when the user clicks an \"add\" button it runs JavaScript that adds a new form (which is part o

15条回答
  •  北海茫月
    2020-11-22 03:34

    One option would be to create a formset with every possible form, but initially set the unrequired forms to hidden - ie, display: none;. When it's necessary to display a form, set it's css display to block or whatever is appropriate.

    Without know more details of what your "Ajax" is doing, it's hard to give a more detailed response.

提交回复
热议问题