Skip to content

Conversation

smile675
Copy link

@smile675 smile675 commented Feb 1, 2025

Hi, first of all thanks for your project.
I was struggling with django form_set for last two weeks, until i found your project and everything became clear to me.
However, while working on my project I found there could be some upgrade on your project, might be helpful to others.

issue: while adding new row in the formset; both in images and variation; user is not able to remove newly added row, unless the keep the input empty and submit.

to solve this i have done the follows.

  1. change 'extra=0' in the formset defination.
  2. added remove button to the row in the else condition of {% if formss.instance.pk %}
    this enables option to removing newly added row in the formset. When there is an pk that means the row coming from database, so, display 'delete' button. when there is no pk, that means the row is not from database (newly added), so it display 'remove' button.
  3. added jQuery logic to remove the row from the ui, which does not effect the database, just remove it from client.

I have tested by adding and editing some products. so, ignore the image added into the media dir.

Again thanks for your work man.
you saved me by your project. specially, when the formset is so tricky to manage.

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

Successfully merging this pull request may close these issues.

1 participant