From 527a49e3b8837a5676e11a0c71d395a2261cef65 Mon Sep 17 00:00:00 2001 From: Halo Dev Bot <87291978+halo-dev-bot@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:10:11 +0800 Subject: [PATCH] [release-2.19] fix: correct boolean value display issue in formkit selector component (#6630) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an automated cherry-pick of #6624 /assign LIlGG ```release-note 修复 FormKit Select 组件中布尔值的显示问题。 ``` --- ui/src/formkit/inputs/select/SelectMain.vue | 23 +++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/ui/src/formkit/inputs/select/SelectMain.vue b/ui/src/formkit/inputs/select/SelectMain.vue index 44ef2ae4d..b5cbabae4 100644 --- a/ui/src/formkit/inputs/select/SelectMain.vue +++ b/ui/src/formkit/inputs/select/SelectMain.vue @@ -555,6 +555,22 @@ watch( } ); +const enableAutoSelect = () => { + if (!selectProps.autoSelect) { + return false; + } + if (selectProps.multiple || selectProps.placeholder) { + return false; + } + + const value = props.context.node.value; + if (value === void 0 || value === null) { + return true; + } + + return false; +}; + watch( () => options.value, async (newOptions) => { @@ -563,13 +579,8 @@ watch( if (selectedOption) { selectOptions.value = selectedOption; } - const isAutoSelect = - selectProps.autoSelect && - !selectProps.multiple && - !selectProps.placeholder && - !props.context.node.value; - if (isAutoSelect) { + if (enableAutoSelect()) { // Automatically select the first option when the selected value is empty. const autoSelectedOption = getAutoSelectedOption(); if (autoSelectedOption) {