Skip to content

Commit

Permalink
Use the new column-select component in FormData for multiple select
Browse files Browse the repository at this point in the history
This allows for easier multiselect with added ease for range select.
Fixes #17947
  • Loading branch information
ahmedhamidawan committed Apr 16, 2024
1 parent eeca0f1 commit 0f8c379
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 8 additions & 1 deletion client/src/components/Form/Elements/FormData/FormData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { orList } from "@/utils/strings";
import type { DataOption } from "./types";
import { BATCH, SOURCE, VARIANTS } from "./variants";
import FormSelection from "../FormSelection.vue";
import FormSelect from "@/components/Form/Elements/FormSelect.vue";
library.add(faCopy, faFile, faFolder, faCaretDown, faCaretUp, faExclamation, faLink, faUnlink);
Expand Down Expand Up @@ -502,7 +503,7 @@ const noOptionsWarningMessage = computed(() => {
</div>

<FormSelect
v-if="currentVariant"
v-if="currentVariant && !currentVariant.multiple"
v-model="currentValue"
class="align-self-start"
:multiple="currentVariant.multiple"
Expand All @@ -515,6 +516,12 @@ const noOptionsWarningMessage = computed(() => {
</BAlert>
</template>
</FormSelect>
<FormSelection
v-else-if="currentVariant?.multiple"
v-model="currentValue"
:data="formattedOptions"
optional
multiple />

<template v-if="currentVariant && currentVariant.batch !== BATCH.DISABLED">
<BFormCheckbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const searchRegex = computed(() => {
/** Wraps value prop so it can be set, and always returns an array */
const selected = computed({
get() {
return Array.isArray(props.value) ? props.value : [props.value];
return props.value === null ? [] : Array.isArray(props.value) ? props.value : [props.value];
},
set(value) {
emit("input", value);
Expand Down Expand Up @@ -142,7 +142,15 @@ async function deselectOption(event: MouseEvent, index: number) {
const [option] = selectedOptionsFiltered.value.splice(index, 1);
if (option) {
const i = selected.value.indexOf(option.value);
const i = selected.value.findIndex((selectedValue) => {
if (typeof selectedValue === "string") {
return selectedValue === option.value;
} else if (typeof selectedValue === "object" && typeof option.value === "object") {
// in case values are objects, compare their ids (if they have the 'id' property)
return selectedValue?.id === option.value?.id;
}
return false;
});
selected.value = selected.value.flatMap((value, index) => (index === i ? [] : [value]));
}
Expand Down

0 comments on commit 0f8c379

Please sign in to comment.