Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete links are not displayed for Django Formsets used together with django-dynamic-formset

I am following this tutorial which shows how to work with Formsets in Django. The tutorial uses django-dynamic-formset JQuery plugin which enables edition of formsets as in Django admin.

Let's say I have following form:

<form  enctype="multipart/form-data" method="post">
   {% csrf_token %}

       {% for place_form in places_formset %}
            <div class="place_formset">
                <div class="required field">
                  <label>{{ place_form.name.label }}</label>
                  <div class="ui icon input">
                    {{ place_form.name }}
                  </div>
                </div>
            </div>
        {% endfor %}

       {{ places_formset.management_form }}

    <br>
    <button  type="submit">Save changes</button>

When I render the form I get "Add item" link which allows me to add another form to the formset.(means also that js and JQuery is loaded and working) but I don't see links which should remove each form instance.

Here there is explanation about deletion of items from inline formsets but nothing is said about regular formsets.

What I have done so far:

1.I have tried to include:

   {{ place_form.DELETE }}

into the form thinking that django-dynamic-formset will replace all the rendered checkboxes with "remove" links but it didn't happen.

2.Also I have tried to render set class with explicit can_delete but it didn't solve the problem:

  PlaceFormSet = formset_factory(PlaceForm, can_delete=True)

3.Instead of rendering the form field by field I have tried to render it with {{ places_formset }}. In this case the form renders with delete checkboxes, but there are not replaced with remove links. Also add item link has disappeared.

What else can I do to enable remove links?

like image 479
Alexander Tyapkov Avatar asked Oct 17 '22 18:10

Alexander Tyapkov


1 Answers

Is your formset hidden when the page is loaded? If so the following statement within jquery.formset.js returns false even after the form is made visible.

if (row.is(':visible')) {
    insertDeleteLink(row);
    applyExtraClasses(row, i);
}

This has been raised and there is an open issue https://github.com/elo80ka/django-dynamic-formset/issues/54

Until the issue is resolved I have removed the if statement from my local copy of jquery.formset.js

like image 78
firstTimeCaller Avatar answered Oct 21 '22 04:10

firstTimeCaller