1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-20 13:49:39 +02:00

Fix AND prefix on rule form (#2234)

* Fix AND prefix on rule form

This new condition prefix data target is used to ensure the AND prefix is added/removed to additional conditions/groups when there aren't any saved conditions yet.

* Ensure the condition group "Add condition" button is type button to avoid form submission

* Add prefix update when removing a subcondition

* Use data condition to update the prefix on conditions, condition groups, and subconditions

* Use condition remove instead of element remove for condition groups so prefix logic runs

* Add back explicit show_prefixes to ensure subconditions never have a prefix

* Run the prefix update runs on a load of a form, which handles prefixes on an edit since no conditions change

* Ensure saved items that are marked for removal don't impact the index

* Simplify logic since we don't process subconditions

* Clean up comments

* Add primary_condition_title field to rule model
This commit is contained in:
Alex Hatzenbuhler 2025-05-13 09:34:41 -05:00 committed by GitHub
parent df8e22afe9
commit 30d3eef67f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 70 additions and 18 deletions

View file

@ -21,12 +21,23 @@ export default class extends Controller {
}
remove(e) {
// Find the parent rules controller before removing the condition
const rulesEl = this.element.closest('[data-controller~="rules"]');
if (e.params.destroy) {
this.destroyFieldTarget.value = true;
this.element.classList.add("hidden");
} else {
this.element.remove();
}
// Update the prefixes of all conditions from the parent rules controller
if (rulesEl) {
const rulesController = this.application.getControllerForElementAndIdentifier(rulesEl, "rules");
if (rulesController && typeof rulesController.updateConditionPrefixes === "function") {
rulesController.updateConditionPrefixes();
}
}
}
handleConditionTypeChange(e) {