elo80ka / django-dynamic-formset

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

can't delete or add #144

Open AHAPX opened 7 years ago

AHAPX commented 7 years ago

Hi. Your script works good for new records, but than I try to edit it, I have a problem.

if I use in template:

    <div class="event-dates-formset">
    {{ event_dates_formset|crispy }}
    </div>

<script src="{% static 'jquery.formset.js' %}"></script>
<script type="text/javascript">
    $('.event-dates-formset').formset({
        prefix: '{{ event_dates_formset.prefix }}'
    });
</script>

I can delete existed record in formset, but if I add new one, after POST it's not saved

If I use:

    <div class="event-dates-formset">
    {% for dt_form in event_dates_formset.forms %}
        {% if dt_form.instance.pk %}{{ dt_form.DELETE }}{% endif %}
        {{ dt_form|crispy }}
    {% endfor %}
    </div>

I can add new ones, but if I delete one, after POST it's still there.

Do I something wrong?

rawteech commented 5 years ago

Not the most efficient solution, but I would suggest comparing the POST data with what's in the DB then delete what's not in the POST data