Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-2.19] fix: resolve incorrect display of options in formkit selector with async data #6631

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ui/src/formkit/inputs/select/SelectDropdownContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ const filterOptions = computed(() => {
}

const options = props.options.filter((option) => {
return option.label
.toLocaleLowerCase()
.includes(keyword.toLocaleLowerCase());
if (option.label) {
return option.label
.toLocaleLowerCase()
.includes(keyword.toLocaleLowerCase());
}
return false;
});

if (props.allowCreate) {
Expand Down
17 changes: 12 additions & 5 deletions ui/src/formkit/inputs/select/SelectMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,18 @@ watch(
}
);

watch(
() => options.value,
async (newOptions) => {
if (newOptions && newOptions.length > 0) {
const selectedOption = await fetchSelectedOptions();
if (selectedOption) {
selectOptions.value = selectedOption;
}
}
}
);

const enableAutoSelect = () => {
if (!selectProps.autoSelect) {
return false;
Expand All @@ -575,11 +587,6 @@ watch(
() => options.value,
async (newOptions) => {
if (newOptions && newOptions.length > 0) {
const selectedOption = await fetchSelectedOptions();
if (selectedOption) {
selectOptions.value = selectedOption;
}

if (enableAutoSelect()) {
// Automatically select the first option when the selected value is empty.
const autoSelectedOption = getAutoSelectedOption();
Expand Down
Loading