app/assets/javascripts/headmin.js in headmin-0.5.5 vs app/assets/javascripts/headmin.js in headmin-0.5.6

- old
+ new

@@ -10094,22 +10094,21 @@ }; // app/assets/javascripts/headmin/controllers/media_controller.js var media_controller_default = class extends Controller { static get targets() { - return ["item", "template", "thumbnails", "modalButton", "placeholder", "validationInput", "count", "editButton"]; + return ["item", "template", "thumbnails", "modalButton", "placeholder", "count", "editButton"]; } connect() { document.addEventListener("mediaSelectionSubmitted", (event) => { if (event.detail.name === this.element.dataset.name) { this.selectItems(event.detail.items); } }); if (this.hasSorting()) { this.initSortable(); } - this.validate(); } destroy(event) { const item = event.currentTarget.closest("[data-media-target='item']"); this.destroyItem(item); } @@ -10146,40 +10145,11 @@ } postProcess() { this.resetPositions(); this.syncIds(); this.togglePlaceholder(); - this.validate(); } - validate() { - this.clearValidation(); - if (this.element.dataset.required === "0") - return; - this.validateMinimum(); - this.validateMaximum(); - } - clearValidation() { - this.validationInputTarget.setCustomValidity(""); - } - validateMinimum() { - const count = this.activeItems().length; - if (count < this.minActiveItems()) { - this.validationInputTarget.setCustomValidity(this.validationInputTarget.dataset.minMessage); - } - } - validateMaximum() { - const count = this.activeItems().length; - if (count > this.maxActiveItems()) { - this.validationInputTarget.setCustomValidity(this.validationInputTarget.dataset.maxMessage); - } - } - minActiveItems() { - return parseInt(this.element.dataset.min, 10) || 0; - } - maxActiveItems() { - return parseInt(this.element.dataset.max, 10) || Infinity; - } resetPositions() { this.activeItems().forEach((item, index2) => { const positionInput = item.querySelector("input[name*='position']"); if (positionInput) { positionInput.value = index2; @@ -15557,15 +15527,22 @@ event.preventDefault(); const row = event.target.closest(".repeater-row"); if (row.dataset.newRecord === "true") { row.remove(); } else { - row.querySelector("input[name*='_destroy']").value = 1; - row.style.display = "none"; + this.flagRowForDeletion(row); + row.remove(); } this.resetIndices(); this.resetPositions(); this.toggleEmpty(); + } + flagRowForDeletion(row) { + const destroyInput = row.querySelector("input[name*='_destroy']"); + const idInput = row.querySelector("input[name*='[id]']"); + destroyInput.value = 1; + this.listTarget.parentNode.appendChild(destroyInput); + this.listTarget.parentNode.appendChild(idInput); } getTemplate(name) { return this.templateTargets.filter((template) => { return template.dataset.templateName === name; })[0];