Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically added row cannot be saved, deleted row still be saved #161

Open
HPJason opened this issue Jan 26, 2020 · 4 comments
Open

Dynamically added row cannot be saved, deleted row still be saved #161

HPJason opened this issue Jan 26, 2020 · 4 comments

Comments

@HPJason
Copy link

HPJason commented Jan 26, 2020

I am using django 3.0.2.

  1. The row can be added visually for inlineformset in the website, however, the row dynamically added cannot save to database.
  2. The row removed from the inlineformset is just hidden and can still be sent to the database, I don't want this to happen.

Any idea to fix it, thanks.

@a-wip0
Copy link

a-wip0 commented Nov 16, 2020

it still happen in django 3.1

@fbzyx
Copy link

fbzyx commented Dec 25, 2020

Hello. I have the same problem? Did you find a solution?

@vitorfs
Copy link

vitorfs commented Mar 10, 2021

I'm currently only using it for inline formsets within tables

I managed to fix the deletion problem by editing the source code, updating this part of code:

if (del.length) {
    // We're dealing with an inline formset.
    // Rather than remove this form from the DOM, we'll mark it as deleted
    // and hide it, then let Django handle the deleting:
    del.val('on');
    row.hide();
    forms = $('.' + options.formCssClass).not(':hidden');
    totalForms.val(forms.length);
}

To this:

if (del.length) {
    // We're dealing with an inline formset.
    // Rather than remove this form from the DOM, we'll mark it as deleted
    // and hide it, then let Django handle the deleting:
    del.val('on');
    row.hide();
    forms = $('.' + options.formCssClass);
    totalForms.val(forms.length);
}

I was getting a weird behavior when deleting several items because by excluding the hidden rows (marked as deleted) from the totalForms count, Django's formset apis wasn't processing the deletion properly.

@sabitrakhanal
Copy link

sabitrakhanal commented Jun 15, 2021

Having same issue with Django 1.11 and above changes is not helping. @vitorfs
seems like we should not change totalForms count on deletion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants