From de62fd72d94c37004e4a5f55b7c25cedbce1ca29 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Fri, 6 Jan 2023 17:24:08 -0400 Subject: [PATCH] fix: Allow additional draft forms to be added to IPR disclosure edit form (#4952) * chore: Remove commented-out template content * fix: Correctly number newly added draft_form inputs on IPR edit form * fix: Initialize select2 when adding a new field instance --- ietf/ipr/views.py | 4 +-- ietf/static/js/ipr-edit.js | 4 ++- ietf/templates/ipr/details_edit.html | 34 ++++------------------ ietf/templates/ipr/details_edit_draft.html | 14 +++++++++ 4 files changed, 24 insertions(+), 32 deletions(-) create mode 100644 ietf/templates/ipr/details_edit_draft.html diff --git a/ietf/ipr/views.py b/ietf/ipr/views.py index d587eaecd..2450e5313 100644 --- a/ietf/ipr/views.py +++ b/ietf/ipr/views.py @@ -296,7 +296,7 @@ def edit(request, id, updates=None): ipr = get_object_or_404(IprDisclosureBase, id=id).get_child() type = class_to_type[ipr.__class__.__name__] - DraftFormset = inlineformset_factory(IprDisclosureBase, IprDocRel, form=DraftForm, can_delete=True, extra=1) + DraftFormset = inlineformset_factory(IprDisclosureBase, IprDocRel, form=DraftForm, can_delete=True, extra=0) if request.method == 'POST': form = ipr_form_mapping[ipr.__class__.__name__](request.POST,instance=ipr) @@ -316,7 +316,7 @@ def edit(request, id, updates=None): else: valid_formsets = True - if form.is_valid() and valid_formsets: + if form.is_valid() and valid_formsets: updates = form.cleaned_data.get('updates') disclosure = form.save(commit=False) disclosure.save() diff --git a/ietf/static/js/ipr-edit.js b/ietf/static/js/ipr-edit.js index 40ca4e352..9af5b0359 100644 --- a/ietf/static/js/ipr-edit.js +++ b/ietf/static/js/ipr-edit.js @@ -18,7 +18,7 @@ $(document) ["for", "id", "name"].forEach(function (at) { var val = x.attr(at); if (val && val.match("iprdocrel")) { - x.attr(at, val.replace('-1-', '-' + total + '-')); + x.attr(at, val.replace('__prefix__', total.toString())); } }); }); @@ -27,6 +27,8 @@ $(document) totalField.val(total); template.before(el); + + el.find('.select2-field').each((index, element) => setupSelect2Field($(element))); }); function updateRevisions() { diff --git a/ietf/templates/ipr/details_edit.html b/ietf/templates/ipr/details_edit.html index 2dc51bc7e..7caf28f1a 100644 --- a/ietf/templates/ipr/details_edit.html +++ b/ietf/templates/ipr/details_edit.html @@ -131,37 +131,13 @@

{{ draft_formset.management_form }} {% for draft_form in draft_formset %} -
- -
- {{ draft_form.id }} - {{ draft_form.document }} - {% if draft_form.document.errors %}
{{ draft_form.document.errors }}
{% endif %} -
-
- {% bootstrap_field draft_form.revisions class="form-control" placeholder="Revisions, e.g., 04-07" show_help=False show_label=False %} - -
-
- {% bootstrap_field draft_form.sections class="form-control" placeholder="Sections" show_help=False show_label=False %} - -
+
+ {% include "ipr/details_edit_draft.html" with draft_form=draft_form only %}
{% endfor %} - {% comment %} - {% for draft_form in draft_formset %} -
-
{% bootstrap_label draft_form.document.label %}
-
{% bootstrap_field draft_form.document label_class="d-none" show_help=False %}
-
- {% bootstrap_field draft_form.revisions placeholder="Revisions, e.g., 04-07" label_class="d-none" show_help=False %} -
-
- {% bootstrap_field draft_form.sections placeholder="Sections" label_class="d-none" show_help=False %} -
-
- {% endfor %} - {% endcomment %} +
+ {% include "ipr/details_edit_draft.html" with draft_form=draft_formset.empty_form only %} +
diff --git a/ietf/templates/ipr/details_edit_draft.html b/ietf/templates/ipr/details_edit_draft.html new file mode 100644 index 000000000..64e5afe60 --- /dev/null +++ b/ietf/templates/ipr/details_edit_draft.html @@ -0,0 +1,14 @@ +{% load django_bootstrap5 %} +
+ {{ draft_form.id }} + {{ draft_form.document }} + {% if draft_form.document.errors %}
{{ draft_form.document.errors }}
{% endif %} +
+
+ {% bootstrap_field draft_form.revisions class="form-control" placeholder="Revisions, e.g., 04-07" show_help=False show_label=False %} + +
+
+ {% bootstrap_field draft_form.sections class="form-control" placeholder="Sections" show_help=False show_label=False %} + +