From 559acbaa50795396837dceef60c7d5d4ca288c9e Mon Sep 17 00:00:00 2001 From: hatz Date: Sat, 10 May 2025 12:24:22 -0500 Subject: [PATCH] Add prefix update when removing a subcondition --- .../controllers/rule/conditions_controller.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/javascript/controllers/rule/conditions_controller.js b/app/javascript/controllers/rule/conditions_controller.js index 1cffa119..c4717a5c 100644 --- a/app/javascript/controllers/rule/conditions_controller.js +++ b/app/javascript/controllers/rule/conditions_controller.js @@ -21,12 +21,25 @@ export default class extends Controller { } remove(e) { + // Find the parent rules controller before removing the condition + const rulesEl = this.element.closest('[data-controller~="rules"]'); + + // Remove the condition if (e.params.destroy) { this.destroyFieldTarget.value = true; this.element.classList.add("hidden"); } else { this.element.remove(); } + + // Update the prefixes of all siblings from the parent rules controller + if (rulesEl) { + const rulesController = this.application.getControllerForElementAndIdentifier(rulesEl, "rules"); + if (rulesController && typeof rulesController.updateConditionPrefixes === "function") { + rulesController.updateConditionPrefixes(); + console.log("updated prefixes") + } + } } handleConditionTypeChange(e) {