From a35c11446eeb3509f1712e92dc96793155434509 Mon Sep 17 00:00:00 2001 From: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> Date: Fri, 10 Dec 2021 14:56:58 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#3185:=20validateApi=E7=9A=84sendOn?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E4=B8=8D=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#3186)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/cfc/mock/form/formitemFailed.json | 6 ++++++ mock/cfc/mock/form/formitemSuccess.json | 3 +++ src/store/formItem.ts | 5 +++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 mock/cfc/mock/form/formitemFailed.json create mode 100644 mock/cfc/mock/form/formitemSuccess.json diff --git a/mock/cfc/mock/form/formitemFailed.json b/mock/cfc/mock/form/formitemFailed.json new file mode 100644 index 000000000..bf4d4a2db --- /dev/null +++ b/mock/cfc/mock/form/formitemFailed.json @@ -0,0 +1,6 @@ +{ + "status": 422, + "msg": "", + "errors": "当前用户已存在", + "data": null +} diff --git a/mock/cfc/mock/form/formitemSuccess.json b/mock/cfc/mock/form/formitemSuccess.json new file mode 100644 index 000000000..c00582e03 --- /dev/null +++ b/mock/cfc/mock/form/formitemSuccess.json @@ -0,0 +1,3 @@ +{ + "status": 0 +} diff --git a/src/store/formItem.ts b/src/store/formItem.ts index 76768dfed..afa0bdebc 100644 --- a/src/store/formItem.ts +++ b/src/store/formItem.ts @@ -14,6 +14,7 @@ import {str2rules, validate as doValidate} from '../utils/validations'; import {Api, Payload, fetchOptions} from '../types'; import {ComboStore, IComboStore, IUniqueGroup} from './combo'; import {evalExpression} from '../utils/tpl'; +import {isEffectiveApi} from '../utils/api'; import findIndex from 'lodash/findIndex'; import { isArrayChildrenModified, @@ -320,7 +321,7 @@ export const FormItemStore = StoreNode.named('FormItemStore') let validateCancel: Function | null = null; const validate: (data: Object, hook?: any) => Promise = flow( function* validate(data: Object, hook?: any) { - if (self.validating && !self.validateApi) { + if (self.validating && !isEffectiveApi(self.validateApi, data)) { return self.valid; } @@ -334,7 +335,7 @@ export const FormItemStore = StoreNode.named('FormItemStore') doValidate(self.tmpValue, data, self.rules, self.messages, self.__) ); - if (!self.errors.length && self.validateApi) { + if (!self.errors.length && isEffectiveApi(self.validateApi, data)) { if (validateCancel) { validateCancel(); validateCancel = null;