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

Simlutaneous deletion and creation not working #180

Open
pavlutom opened this issue Aug 18, 2020 · 8 comments
Open

Simlutaneous deletion and creation not working #180

pavlutom opened this issue Aug 18, 2020 · 8 comments

Comments

@pavlutom
Copy link

pavlutom commented Aug 18, 2020

If I delete one item and create another in one POST, the new item is not created, only the deletion happens. It works fine if I remove line 95 in src/jquery.formset.js (totalForms.val(forms.length);). This code was introduced in #173. I'm not sure what was the purpose of this line, probably to fix some other error that I didn't notice.

I am using Django 3.0.7

@andyp05
Copy link

andyp05 commented Sep 16, 2020

I am seeing this as well with django 3.1

@alfonsrv
Copy link

alfonsrv commented Oct 7, 2020

Thank god. I could not delete any formset form but the first one because of this line.
Hidden and therefore deleted rows still have to be enumerated in the management header's TOTAL_FORMS, as Django will only consider that amount for rows. Any rows surpassing this value will be disregarded. E.g. if you have two forms and you schedule one for deletion, TOTAL_FORMS updates to 1, which will then in turn result in the second form to be ignored by Django completely.

Reviewing #173, it seems like the author did not implement the library properly into his project, as decrementing beyond the specified amount of min_num is not possible. It is to note that this is mainly due to a sloppy documentation, as django-dynamic-formset not only requires formCssClass to be unique, but also addCssClass, deleteCssClass and possibly even deleteContainerClass. This may be due to an improperly setup selector in the library, but that's at least the current requirement/behavior.

@JhonFrederick
Copy link

If I delete one item and create another in one POST, the new item is not created, only the deletion happens. It works fine if I remove line 95 in src/jquery.formset.js (totalForms.val(forms.length);). This code was introduced in #173. I'm not sure what was the purpose of this line, probably to fix some other error that I didn't notice.

I am using Django 3.0.7

I had the same problem, I spent hours looking for the problem and as you mention everything works fine for me if the line 95 src/jquery.formset.js (totalForms.val(forms.length);) is removed, I regard that code should be removed and another solution should be looked if it was introduced to fix some error.

@karlos-perez
Copy link

I solved this problem without deleting the code. I assigned unique CSS class name to formCssClass for each formset as in Django Dynamic Formsets documentation:
$(".inline.{{ log_form.prefix }}").formset({
prefix: '{{ log_form.prefix }}',
formCssClass: 'dynamic-formset-{{ log_form.prefix }}'})`

@systemallica
Copy link

Just here to add that indeed deleting (totalForms.val(forms.length);) from the code did the trick for me.

@nick-tao
Copy link

Thanks for this @pavlutom

I was having the same problem. Removing this line: totalForms.val(forms.length); solved the issue.

@Yuri-Lima
Copy link

For god Sake, guys. Thanks Million for that solution.
Removing the line 95 has working PERFECT.
It save me a lot time.

Thanks Million Again.

@Yuri-Lima
Copy link

I solved this problem without deleting the code. I assigned unique CSS class name to formCssClass for each formset as in Django Dynamic Formsets documentation:
$(".inline.{{ log_form.prefix }}").formset({
prefix: '{{ log_form.prefix }}',
formCssClass: 'dynamic-formset-{{ log_form.prefix }}'})`

@karlos-perez, your solution probably has been working. but maybe you didn't understand what was the main issue. Not sure of course.
I'm just saying it because i was trying to solve using so many ways from Django tools, but i do realize that problem came from the JS file.
So, up to now. I do recommend use the solution which those guys have discovered.
Anyway thanks @karlos-perez

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

8 participants