From 577438f9ea0f25f5596aa1bb8e262d3c5a30173f Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 7 Jul 2021 09:39:29 +0200 Subject: Preventive file - inline forms --- ishtar_common/static/js/ishtar.js | 23 ++++++++++++++++++++++ ishtar_common/templates/base.html | 4 ++++ .../templates/blocks/bs_field_snippet.html | 2 +- .../templates/blocks/bs_formset_snippet.html | 20 ++++++++++++++++++- .../templates/ishtar/forms/base_form.html | 5 +++++ 5 files changed, 52 insertions(+), 2 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index 897356fe3..3fa293deb 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -1874,4 +1874,27 @@ var update_select_widget = function(input_name, values, only_values, excluded_va } } $("#id_" + input_name).html(options); +}; + +var inline_register_add_button = function(slug){ + let inline_form = document.querySelectorAll(".form-" + slug); + let inline_container = document.querySelector("#formset-container-" + slug); + let inline_add_button = document.querySelector("#add-form-" + slug); + let inline_div_add_button = document.querySelector("#div-add-form-" + slug); + let inline_total_forms = document.querySelector("#id_" + slug + "-TOTAL_FORMS"); + let inline_form_num = inline_form.length - 1; + inline_add_button.addEventListener( + 'click', function(e){ + e.preventDefault(); + let new_form = inline_form[0].cloneNode(true); + let form_regex_var = slug + '(\\d){1}-'; + let form_regex = new RegExp(form_regex_var, 'g'); + inline_form_num++; + console.log(new_form); + new_form.innerHTML = new_form.innerHTML.replace( + form_regex, slug + `-${inline_form_num}-`); + inline_container.insertBefore(new_form, inline_div_add_button); + inline_total_forms.setAttribute('value', `${inline_form_num+1}`); + } + ); }; \ No newline at end of file diff --git a/ishtar_common/templates/base.html b/ishtar_common/templates/base.html index f9feef533..af4396be3 100644 --- a/ishtar_common/templates/base.html +++ b/ishtar_common/templates/base.html @@ -265,6 +265,10 @@
+ diff --git a/ishtar_common/templates/blocks/bs_field_snippet.html b/ishtar_common/templates/blocks/bs_field_snippet.html index dcee87f7f..beecf624f 100644 --- a/ishtar_common/templates/blocks/bs_field_snippet.html +++ b/ishtar_common/templates/blocks/bs_field_snippet.html @@ -1,5 +1,5 @@ {% load i18n %} -
{% if field.label %}{{ field.label_tag }}{% endif %} {% if extra_field_label %}{% endif %} diff --git a/ishtar_common/templates/blocks/bs_formset_snippet.html b/ishtar_common/templates/blocks/bs_formset_snippet.html index 0d089ee1b..3a7e537d3 100644 --- a/ishtar_common/templates/blocks/bs_formset_snippet.html +++ b/ishtar_common/templates/blocks/bs_formset_snippet.html @@ -1,6 +1,9 @@ {% load i18n from_dict %} -
+
+ {{ formset.non_form_errors.as_ul }} + {{ formset.management_form }} {% for form in formset %} +
{% if form.non_field_errors and not no_error %} {% endfor %} + {% if formset.dynamic_add %} +
+
+ +
+
+ + {% endif %}
diff --git a/ishtar_common/templates/ishtar/forms/base_form.html b/ishtar_common/templates/ishtar/forms/base_form.html index fb1fc997f..3f069e7d6 100644 --- a/ishtar_common/templates/ishtar/forms/base_form.html +++ b/ishtar_common/templates/ishtar/forms/base_form.html @@ -23,10 +23,15 @@ {% endif %} {% block form_head %} {% endblock %} + {% block bs_form %} {% bs_form form 0 True %} + {% endblock %} + {% block bs_form_inlines %} {% for inline in inline_forms %} +

{{inline.form_label}}

{% bs_formset inline 0 True %} {% endfor %} + {% endblock %}
{% endblock %} -- cgit v1.2.3