Implement a filter for category (#215)

- Also implement an is empty/is null condition.
This commit is contained in:
soky srm
2025-10-22 17:03:00 +02:00
committed by GitHub
parent 8cd109a5b2
commit 192a3b6890
7 changed files with 120 additions and 11 deletions

View File

@@ -11,6 +11,11 @@ export default class extends Controller {
"subConditionsList",
];
connect() {
// Hide value field on initial load if operator is "is_null"
this.#toggleValueFieldVisibility();
}
addSubCondition() {
const html = this.subConditionTemplateTarget.innerHTML.replaceAll(
"IDX_CHILD_PLACEHOLDER",
@@ -52,6 +57,11 @@ export default class extends Controller {
}
this.#updateOperatorsField(conditionFilter);
this.#toggleValueFieldVisibility();
}
handleOperatorChange(e) {
this.#toggleValueFieldVisibility();
}
get valueInputEl() {
@@ -112,4 +122,18 @@ export default class extends Controller {
#uniqueKey() {
return Date.now();
}
#toggleValueFieldVisibility() {
const operator = this.operatorSelectTarget.value;
if (operator === "is_null") {
this.filterValueTarget.classList.add("hidden");
// Clear the value since it's not needed
if (this.valueInputEl) {
this.valueInputEl.value = "";
}
} else {
this.filterValueTarget.classList.remove("hidden");
}
}
}