Skip to content

Commit

Permalink
fix: resolve incorrect display of options in formkit selector with as…
Browse files Browse the repository at this point in the history
…ync data (#6629)

#### What type of PR is this?

/kind bug
/area ui
/milestone 2.20.x

#### What this PR does / why we need it:

为 formkit select 组件优化逻辑,目前将可以监听到 options 的变化,用于在变化时设置值。用于解决当 options 是异步获取,而 value 是初始设置时,无法显示正常的 label。

#### How to test it?

测试 options 比设置 value 晚时,数据能否正常显示 label。

#### Does this PR introduce a user-facing change?
```release-note
解决当 formkit select 组件中的 options 延迟设置时无法正常回显的问题。
```
  • Loading branch information
LIlGG authored Sep 10, 2024
1 parent 3c785cb commit b02ab8d
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 b02ab8d

Please sign in to comment.