From f17f17d8de74c07e24e7dc3f7b711e9cc1183f18 Mon Sep 17 00:00:00 2001
From: imperosol
Date: Sat, 7 Mar 2026 16:21:18 +0100
Subject: [PATCH] use dynamic formset for product action formset
---
.../bundled/core/dynamic-formset-index.ts | 3 +
core/templates/core/base.jinja | 4 +-
counter/forms.py | 3 +-
counter/templates/counter/product_form.jinja | 81 ++++++++++++-------
locale/fr/LC_MESSAGES/django.po | 8 ++
5 files changed, 68 insertions(+), 31 deletions(-)
diff --git a/core/static/bundled/core/dynamic-formset-index.ts b/core/static/bundled/core/dynamic-formset-index.ts
index d503c55a..6b71e25f 100644
--- a/core/static/bundled/core/dynamic-formset-index.ts
+++ b/core/static/bundled/core/dynamic-formset-index.ts
@@ -21,6 +21,9 @@ document.addEventListener("alpine:init", () => {
* - a button with `@click="addForm"`
* - you may also have one or more buttons with `@click="removeForm(element)"`,
* where `element` is the HTML element containing the form.
+ *
+ * For an example of how this is used, you can have a look to
+ * `counter/templates/counter/product_form.jinja`
*/
Alpine.data("dynamicFormSet", (config?: Config) => ({
init() {
diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja
index 34a8040b..025dacdf 100644
--- a/core/templates/core/base.jinja
+++ b/core/templates/core/base.jinja
@@ -35,8 +35,8 @@
-
-
+
+
diff --git a/counter/forms.py b/counter/forms.py
index 1d9fa8a0..33bfd51a 100644
--- a/counter/forms.py
+++ b/counter/forms.py
@@ -291,7 +291,8 @@ ScheduledProductActionFormSet = forms.modelformset_factory(
absolute_max=None,
can_delete=True,
can_delete_extra=False,
- extra=2,
+ extra=0,
+ min_num=1,
)
diff --git a/counter/templates/counter/product_form.jinja b/counter/templates/counter/product_form.jinja
index f3d3728c..ffd751c0 100644
--- a/counter/templates/counter/product_form.jinja
+++ b/counter/templates/counter/product_form.jinja
@@ -1,5 +1,44 @@
{% extends "core/base.jinja" %}
+{% block additional_js %}
+
+{% endblock %}
+
+
+{% macro action_form(form) %}
+
+{% endmacro %}
+
+
{% block content %}
{% if object %}
{% trans name=object %}Edit product {{ name }}{% endtrans %}
@@ -25,34 +64,20 @@
- {{ form.action_formset.management_form }}
- {%- for action_form in form.action_formset.forms -%}
-