Skip to content

Commit

Permalink
[release-2.19] fix: resolve incorrect display of options in formkit s…
Browse files Browse the repository at this point in the history
…elector with async data (#6631)

This is an automated cherry-pick of #6629

/assign LIlGG

```release-note
解决当 formkit select 组件中的 options 延迟设置时无法正常回显的问题。
```
  • Loading branch information
LIlGG authored Sep 10, 2024
1 parent 527a49e commit a5ff816
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
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

0 comments on commit a5ff816

Please sign in to comment.