From d4b4c7d3af5443f7f9d541d452be13bae46e7eaa Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Thu, 10 Aug 2023 08:50:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20#7443=20=E5=BC=95?= =?UTF-8?q?=E5=8F=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/renderers/Form.tsx | 35 +++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/packages/amis-core/src/renderers/Form.tsx b/packages/amis-core/src/renderers/Form.tsx index ee3c1d1cf..3d5c0e022 100644 --- a/packages/amis-core/src/renderers/Form.tsx +++ b/packages/amis-core/src/renderers/Form.tsx @@ -847,7 +847,9 @@ export default class Form extends React.Component { this.hooks['validate'] || [], forceValidate, throwErrors, - __(filter(messages && messages.validateFailed, store.data)) + typeof messages?.validateFailed === 'string' + ? __(filter(messages.validateFailed, store.data)) + : undefined ) .then((result: boolean) => { if (result) { @@ -892,7 +894,9 @@ export default class Form extends React.Component { return store.submit( fn, this.hooks['validate'] || [], - __(filter(messages && messages.validateFailed, store.data)), + typeof messages?.validateFailed === 'string' + ? __(filter(messages.validateFailed, store.data)) + : undefined, validateErrCb, throwErrors ); @@ -1172,8 +1176,14 @@ export default class Form extends React.Component { return store .saveRemote(action.api || (api as Api), values, { - successMessage: filter(saveSuccess, store.data), - errorMessage: filter(saveFailed, store.data), + successMessage: + typeof saveSuccess === 'string' + ? filter(saveSuccess, store.data) + : undefined, + errorMessage: + typeof saveFailed === 'string' + ? filter(saveFailed, store.data) + : undefined, onSuccess: async (result: Payload) => { // result为提交接口返回的内容 const dispatcher = await dispatchEvent( @@ -1303,20 +1313,21 @@ export default class Form extends React.Component { if (!isEffectiveApi(action.api)) { return env.alert(__(`当 actionType 为 ajax 时,请设置 api 属性`)); } + let successMsg = + (action.messages && action.messages.success) || saveSuccess; + let failMsg = (action.messages && action.messages.failed) || saveFailed; return store .saveRemote(action.api as Api, data, { successMessage: __( - filter( - (action.messages && action.messages.success) || saveSuccess, - store.data - ) + typeof successMsg === 'string' + ? filter(successMsg, store.data) + : undefined ), errorMessage: __( - filter( - (action.messages && action.messages.failed) || saveFailed, - store.data - ) + typeof failMsg === 'string' + ? filter(failMsg, store.data) + : undefined ) }) .then(async response => {