Quellcode durchsuchen

Move InlinePanel child initialisation into the InlinePanel constructor

Matt Westcott vor 2 Jahren
Ursprung
Commit
2335d28b7c

+ 12 - 0
client/src/components/InlinePanel/index.js

@@ -18,6 +18,18 @@ export class InlinePanel extends ExpandingFormset {
   constructor(opts) {
     super(opts.formsetPrefix, opts);
     this.formsElt = $('#' + opts.formsetPrefix + '-FORMS');
+
+    for (let i = 0; i < this.formCount; i += 1) {
+      const childPrefix = this.opts.emptyChildFormPrefix.replace(
+        /__prefix__/g,
+        i,
+      );
+      this.initChildControls(childPrefix);
+    }
+
+    this.updateChildCount();
+    this.updateMoveButtonDisabledStates();
+    this.updateAddButtonState();
   }
 
   initChildControls(prefix) {

+ 0 - 7
wagtail/admin/templates/wagtailadmin/panels/inline_panel.html

@@ -48,12 +48,5 @@
             canOrder: {% if can_order %}true{% else %}false{% endif %},
             maxForms: {{ self.formset.max_num|unlocalize }}
         });
-
-        {% for child in self.children %}
-            panel.initChildControls("{{ child.form.prefix }}");
-        {% endfor %}
-        panel.updateChildCount();
-        panel.updateMoveButtonDisabledStates();
-        panel.updateAddButtonState();
     })();
 </script>

+ 0 - 7
wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/includes/searchpromotions_formset.js

@@ -5,11 +5,4 @@ $(function () {
     emptyChildFormPrefix: '{{ formset.empty_form.prefix }}',
     canOrder: true,
   });
-
-  // {# Ensure eslint/prettier ignore the Django template syntax by treating them as comments, template for loop will still be executed by Django #}
-  // {% for form in formset.forms %}
-  panel.initChildControls('{{ formset.prefix }}-{{ forloop.counter0 }}');
-  // {% endfor %}
-
-  panel.updateMoveButtonDisabledStates();
 });