From 152dd0716c97a77bd1e2d29b30597892e552bae6 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Sat, 20 May 2023 09:48:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20form=20submit=20?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E8=A7=A6=E5=8F=91=E6=97=B6=E6=9C=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20Close:=20#6901?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/renderers/Form.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/amis-core/src/renderers/Form.tsx b/packages/amis-core/src/renderers/Form.tsx index c57ea3e4c..1c315d1d6 100644 --- a/packages/amis-core/src/renderers/Form.tsx +++ b/packages/amis-core/src/renderers/Form.tsx @@ -1052,6 +1052,7 @@ export default class Form extends React.Component { if (data === this.props.data) { data = store.data; } + if (Array.isArray(action.required) && action.required.length) { /** 如果是按钮指定了required,则校验前先清空一下遗留的校验报错 */ store.clearErrors(); @@ -1085,6 +1086,14 @@ export default class Form extends React.Component { action.actionType === 'reset-and-submit' || action.actionType === 'clear-and-submit' ) { + // 配了submit事件的表示将提交逻辑全部托管给事件 + const {dispatchEvent, onEvent} = this.props; + const submitEvent = onEvent?.submit?.actions?.length; + const dispatcher = await dispatchEvent('submit', this.props.data); + if (dispatcher?.prevented || submitEvent) { + return; + } + store.setCurrentAction(action); if (action.actionType === 'reset-and-submit') { @@ -1873,13 +1882,6 @@ export class FormRenderer extends Form { // return; // } - // 配了submit事件的表示将提交逻辑全部托管给事件 - const {dispatchEvent, onEvent} = this.props; - const submitEvent = onEvent?.submit?.actions?.length; - const dispatcher = await dispatchEvent('submit', this.props.data); - if (dispatcher?.prevented || submitEvent) { - return; - } if (action.target && action.actionType !== 'reload') { const scoped = this.context as IScopedContext;