elo80ka / django-dynamic-formset

A jQuery plugin that allows you dynamically add new forms to a rendered django formset.
675 stars 309 forks source link

No remove button and add won't add form #179

Open julialoh opened 4 years ago

julialoh commented 4 years ago

Does this plugin work with Django 3.0.8? I followed this tutorial here: https://dev.to/zxenia/django-inline-formsets-with-class-based-views-and-crispy-forms-14o6 although my end goal is to have two formsets on. the same page. Right now, I have my parent form and one formset with the option to "add another." However, when.I click "add another," nothing happens and there's also no option for "remove." Any help would be greatly appreciated! Thank you

cpina commented 4 years ago

I'm just a uswer of django-dynamic-formset here. Yes, it works with Django 3.0.8. I haven't properly read the link but I use it with Django 3.0.8 and django-crispy-forms. Check on the Javascript console if there is any error message when clicking "add another". Hopefully you can find a problem and see it.

And to say something easy to make a mistake: make sure that this line: $('.formset_row-{{ formset.prefix }}') generates the selector for one of your forms (check via the generated HTML, Javascript console, etc.).

Hopefully something has helped!

julialoh commented 4 years ago

Hello, thank you so much for the response! I unfortunately cannot find an error in the Javascript console when I click "add another." Could I possibly post some code to review?

cpina commented 4 years ago

I can't find here on Github the latest email notification from this thread: Ah, I found the bug. in $('.formset_row-{{ formset.prefix }}'), it doesn't take in the fields which is generated in the HTML. So for instance, the id's in the HTML are like as follows: id_request_elements_0-disks, id_request_elements_0-customer, etc. but the code looks like $('.formset_row-request_elements').formset({ when generated. Do you know how to fix this?

If you still have this problem: check the documentation on what to have in the $('what should be here').formset() : https://github.com/elo80ka/django-dynamic-formset/blob/master/docs/usage.rst (it doesn't need to have the ids of the elements as I think that you suggested).