Discussion:
Add forms to Django formset dynamically with 'Add' button
valentin jungbluth
2018-11-12 15:02:04 UTC
Permalink
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 :

[image: forms.png]


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

[image: main.png]


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

[image: html.png]


And I have *javascript function* :

[image: 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
--
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.
oon arfiandwi
2018-11-12 16:23:16 UTC
Permalink
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
Post by valentin jungbluth
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.
[image: forms.png]
[image: main.png]
[image: html.png]
[image: 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 !
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
--
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
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
<https://groups.google.com/d/msgid/django-users/f2fde589-cd12-4dad-9837-e6b6de4a0d30%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/CACUNLpXWJcKPy5oVB336VvtWYD5fLYKgDgugZSji%3DcdaT84H%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
valentin jungbluth
2018-11-12 16:43:57 UTC
Permalink
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 :

[image: html2.png]

This is my new JS part :

[image: js2.png]

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

[image: main2.png]
--
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/952582be-d1b7-4107-88e8-b9e2a834a0e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...