From cee386941b5328f4f9823cd5ba885b9a0b9770ca Mon Sep 17 00:00:00 2001 From: Kenny Wolf Date: Tue, 6 Sep 2022 11:06:29 +0200 Subject: [PATCH] Create for loop to initialize multiple textareas In some applications there may be multiple textareas to add in a form. --- .../django-editorjs-fields/js/django-editorjs-fields.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/django_editorjs_fields/static/django-editorjs-fields/js/django-editorjs-fields.js b/django_editorjs_fields/static/django-editorjs-fields/js/django-editorjs-fields.js index dd82a3f0..c90cc0d0 100644 --- a/django_editorjs_fields/static/django-editorjs-fields/js/django-editorjs-fields.js +++ b/django_editorjs_fields/static/django-editorjs-fields/js/django-editorjs-fields.js @@ -163,10 +163,12 @@ // Event if (typeof django === "object" && django.jQuery) { django.jQuery(document).on("formset:added", function (event, $row) { - var textarea = $row.find("[data-editorjs-textarea]").get(0) + var areas = $row.find("[data-editorjs-textarea]").get() - if (textarea) { - initEditorJsField(textarea) + if (areas) { + for (let i = 0; i < areas.length; i++) { + initEditorJsField(areas[i]) + } } }) }