From fbd07c8743b89038282feaac2f6377ba6bfce9bd Mon Sep 17 00:00:00 2001 From: guerler Date: Tue, 18 Apr 2023 11:19:17 +0300 Subject: [PATCH] Account for nested options in select all helper --- .../Elements/FormDrilldown/FormDrilldown.vue | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/client/src/components/Form/Elements/FormDrilldown/FormDrilldown.vue b/client/src/components/Form/Elements/FormDrilldown/FormDrilldown.vue index bd6ae89a234..194c635d442 100644 --- a/client/src/components/Form/Elements/FormDrilldown/FormDrilldown.vue +++ b/client/src/components/Form/Elements/FormDrilldown/FormDrilldown.vue @@ -38,7 +38,7 @@ const currentValue = computed({ }, }); -function handleClick(value: string) { +function handleClick(value: string): void { if (props.multiple) { const newValue = currentValue.value.slice(); const index = newValue.indexOf(value); @@ -57,14 +57,21 @@ function handleClick(value: string) { } } -function selectAll(selected: boolean) { +function selectAll(selected: boolean): void { const newValue: string[] = []; if (selected) { - props.options.forEach((option) => { - if (option.value) { - newValue.push(option.value); - } - }); + let options = null; + const stack: Array> = [props.options]; + while ((options = stack.pop())) { + options.forEach((option) => { + if (option.value) { + newValue.push(option.value); + } + if (option.options.length > 0) { + stack.push(option.options); + } + }); + } } emit("input", newValue.length === 0 ? null : newValue); }