From b0db2f746be846050c35cce3f11dd76981480494 Mon Sep 17 00:00:00 2001 From: chenwenhao Date: Fri, 31 May 2024 15:19:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E4=BF=AE=E5=A4=8D=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=9C=BA=E6=99=AF=E4=B8=8B=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0region=E7=9A=84=E6=83=85=E5=86=B5=20issue#10354?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/renderers/Options.tsx | 3 ++- packages/amis-core/src/store/formItem.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/amis-core/src/renderers/Options.tsx b/packages/amis-core/src/renderers/Options.tsx index 62007bb3381d..d072778f1e37 100644 --- a/packages/amis-core/src/renderers/Options.tsx +++ b/packages/amis-core/src/renderers/Options.tsx @@ -434,7 +434,8 @@ export function registerOptionsControl(config: OptionsConfig) { formItem.loadOptionsFromDataScope( props.source as string, props.data, - this.changeOptionValue + this.changeOptionValue, + true ); this.normalizeValue(); diff --git a/packages/amis-core/src/store/formItem.ts b/packages/amis-core/src/store/formItem.ts index b6d18ba4d561..f6aaa13d06cf 100644 --- a/packages/amis-core/src/store/formItem.ts +++ b/packages/amis-core/src/store/formItem.ts @@ -866,7 +866,12 @@ export const FormItemStore = StoreNode.named('FormItemStore') function loadOptionsFromDataScope( source: string, ctx: Record, - onChange?: (value: any) => void + onChange?: ( + value: any, + submitOnChange?: boolean, + changeImmediately?: boolean + ) => void, + clearValue?: boolean ) { let options: any[] = resolveVariableAndFilter(source, ctx, '| raw'); @@ -892,6 +897,13 @@ export const FormItemStore = StoreNode.named('FormItemStore') setOptions(options, onChange, ctx); + // source从数据域获取,同时发生变化时,需要清空当前表单项 + if (clearValue && !self.selectFirst) { + self.selectedOptions.some((item: any) => item.__unmatched) && + onChange && + onChange('', false, true); + } + return options; }