Add forms to Django formset dynamically with 'Add' button

570 views
Skip to first unread message

valentin jungbluth

unread,
Nov 12, 2018, 10:13:05 AM11/12/18
to Django users
Hi guys,

I would like to be able to add dynamically django forms in my formset with Add button.

I tried to write different things but I don't overcome to get the expected result up to now.

I have a formset defined in my forms.py file :

forms.png



Then, I created in my views.py file this function :

main.png

    

Finally, I'm trying to write my template file :

html.png



And I have javascript function :

js.png



I spent lot of time in order to get the expected result but I don't overcome to get it. S I need your help if you could help me.

I don't want to use another library, but I accept JS, AJAX, JQuery or Django answers !

The issue is : 

It displays the first form, but when I want to add a second one by clicking on `Add button`, it doesn't create the second one.

So I assume my Django part is good, but not the JS part ?

Thank you by advance

oon arfiandwi

unread,
Nov 12, 2018, 11:25:14 AM11/12/18
to django...@googlegroups.com
Hi,

about dynamic Django Formset actually it is more about front end (JS) than Django itself.
the only thing related to Django is the formset management (total forms).

when first time I learn about it, I got answer by googling: django dynamic formset jquery
you can evaluate some existing codes in jquery. I created custom code from django-dynamic-formset.
some of them are complete codes on github and gist.

next would be depends on your form, how it displayed to user, how it get input from user.

hope it helps

-- 
sincerely,
O


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f2fde589-cd12-4dad-9837-e6b6de4a0d30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

valentin jungbluth

unread,
Nov 12, 2018, 11:43:57 AM11/12/18
to Django users
I try something and it seems to work ! But I don't overcome to save each forms in my views.py file.

This is my new HTML :

html2.png


This is my new JS part :

js2.png


How I can write this part in order to take into account forms in my formset ?

main2.png


Reply all
Reply to author
Forward
0 new messages