mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 07:25:19 +02:00
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.
This commit is contained in:
parent
a268c5a563
commit
f92c4d62a4
3 changed files with 23 additions and 3 deletions
|
@ -16,6 +16,7 @@ export default class extends Controller {
|
||||||
this.conditionGroupTemplateTarget,
|
this.conditionGroupTemplateTarget,
|
||||||
this.conditionsListTarget,
|
this.conditionsListTarget,
|
||||||
);
|
);
|
||||||
|
this.updateConditionPrefixes();
|
||||||
}
|
}
|
||||||
|
|
||||||
addCondition() {
|
addCondition() {
|
||||||
|
@ -23,6 +24,7 @@ export default class extends Controller {
|
||||||
this.conditionTemplateTarget,
|
this.conditionTemplateTarget,
|
||||||
this.conditionsListTarget,
|
this.conditionsListTarget,
|
||||||
);
|
);
|
||||||
|
this.updateConditionPrefixes();
|
||||||
}
|
}
|
||||||
|
|
||||||
addAction() {
|
addAction() {
|
||||||
|
@ -45,4 +47,15 @@ export default class extends Controller {
|
||||||
#uniqueKey() {
|
#uniqueKey() {
|
||||||
return Date.now();
|
return Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateConditionPrefixes() {
|
||||||
|
const items = this.conditionsListTarget.querySelectorAll('[data-condition-prefix]');
|
||||||
|
items.forEach((el, idx) => {
|
||||||
|
if (idx === 0) {
|
||||||
|
el.classList.add('hidden');
|
||||||
|
} else {
|
||||||
|
el.classList.remove('hidden');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,13 @@
|
||||||
<li data-controller="rule--conditions" data-rule--conditions-condition-filters-value="<%= rule.condition_filters.to_json %>" class="flex items-center gap-3">
|
<li data-controller="rule--conditions" data-rule--conditions-condition-filters-value="<%= rule.condition_filters.to_json %>" class="flex items-center gap-3">
|
||||||
<% if form.index.to_i > 0 && show_prefix %>
|
<% if form.index.to_i > 0 && show_prefix %>
|
||||||
<div class="pl-4">
|
<div class="pl-4">
|
||||||
<span class="font-medium uppercase text-xs">and</span>
|
<span class="font-medium uppercase text-xs" data-condition-prefix>and</span>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<div class="pl-4">
|
||||||
|
<span class="font-medium uppercase text-xs hidden" data-condition-prefix>and</span>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="grow flex gap-2 items-center h-full">
|
<div class="grow flex gap-2 items-center h-full">
|
||||||
<%= form.hidden_field :_destroy, value: false, data: { rule__conditions_target: "destroyField" } %>
|
<%= form.hidden_field :_destroy, value: false, data: { rule__conditions_target: "destroyField" } %>
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,11 @@
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<% unless form.index == 0 %>
|
<% unless form.index == 0 %>
|
||||||
<div class="pl-2">
|
<div class="pl-2">
|
||||||
<span class="font-medium uppercase text-xs">and</span>
|
<span class="font-medium uppercase text-xs" data-condition-prefix>and</span>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<div class="pl-2">
|
||||||
|
<span class="font-medium uppercase text-xs hidden" data-condition-prefix>and</span>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<p class="text-sm text-secondary">match</p>
|
<p class="text-sm text-secondary">match</p>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue