Skip to content

Commit

Permalink
Make manual hiding of -DELETE checkbox more explicit, add reasoning
Browse files Browse the repository at this point in the history
  • Loading branch information
richardebeling committed Sep 18, 2023
1 parent f31c8bf commit e71e544
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions evap/evaluation/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,19 @@
activateTooltips();

// These are workarounds around incompatibilities of django, django-dynamic-formsets, and tomselect.
// tomselect can't handle already tomselect'd forms that were copies made by
// django-dynamic-formsets' "add another" button, so we take a copy of a non-tomselect'd form here
// tomselect can't handle already tomselect'd forms that were copies made by django-dynamic-formsets'
// "add another" button, so we take a copy of a non-tomselect'd form here
const tomSelectRows = document.querySelectorAll(".tomselecttr");

if(tomSelectRows.length != 0) {
var templateForm = tomSelectRows[tomSelectRows.length - 1].cloneNode(true);

// later we use this class to give this to django-dynamic-formsets
// as template and to make sure it does not get tomselect'd
// later we use this class to give this to django-dynamic-formsets as template and to make sure it does not get tomselect'd
templateForm.classList.add("form-template");
templateForm.style.display = "none";

// for some reason django-dynamic-formsets does not hide the checkbox like it should
templateForm.querySelectorAll("checkbox:last-of-type").forEach(checkbox => {checkbox.type = "hidden";});
// django-dynamic-formsets doesn't hide the "delete this row" input in the clone since it's not part of the formset.
templateForm.querySelectorAll("input[id$=-DELETE]").forEach(input => {input.type = "hidden";});

// For some reason, django validates this template if it's part of the form, so we insert the copy outside of the form.
document.querySelector(".tomselectform").insertAdjacentElement("afterend", templateForm);
Expand Down

0 comments on commit e71e544

Please sign in to comment.