- edited description
Can't delete new forms
I'm trying to use this on a model creation page.
When I add a new form, I'm unable to delete it. No formDeleted event is fired. I think it's because the empty_form doesn't come with a delete checkbox.
I tried hacking around this by adding a click handler when a new form gets created, but no formAdded event gets fired either, even though the docs say "When the data-formset-add button is clicked, the formAdded event is fired on the form which was added.".
Not being able to delete new forms prevents validation from succeeding, and the user would have to reload the page and start the form over form scratch
Comments (3)
-
reporter -
repo owner I just test it here, and you can delete forms that have been added, and the events do fire. Make sure that your formset has
can_delete=True
:MyFormSet = formset_factory(MyForm, can_delete=True)
Also make sure the delete checkbox is being printed out in your template, for all forms including the empty form:
{{ formset.empty_form.DELETE }}
The checkbox itself can be hidden by placing it in a
display: none
block.To bind to the formAdded / formDeleted events, I use something like:
$("#formset").formset().on('formAdded', function() { console.log("Form added", this, arguments); }).on('formDeleted', function() { console.log("Form deleted", this, arguments); });
The example application was missing
can_delete=True
in its formset_factory call, so if you were working from that it might explain the issues you were facing. -
repo owner - changed status to resolved
- Log in to comment