From b9b1f539bf6ad846b9b220300b9ab313849a757f Mon Sep 17 00:00:00 2001 From: DuLinRain Date: Sat, 8 Aug 2020 21:57:21 +0800 Subject: [PATCH 1/6] =?UTF-8?q?fix:=20validateOnChange=3Dfalse=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E4=BA=A4=E5=90=8E=E4=BF=AE=E6=94=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=8C=E8=A1=A8=E5=8D=95=E4=B8=8D=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当配置validateOnChange=false时,如果该xiang填写正确,点击提交。这时候修改该项目的内容,让其不符合校验规则,再次点击提交,表单不会校验该项内容。 我认为this.model.valid保存的是发生变化前该项目的状态,当发生变化时,该项model也应该重置。 复现demo: gif: https://github.com/DuLinRain/pictures/blob/master/amis-bug1.gif?raw=true mp4: https://github.com/DuLinRain/pictures/blob/master/amis-bug1.mp4?raw=true 复现代码如下: { "$schema": "https://houtai.baidu.com/v2/schemas/page.json#", "title": "表单验证示例", "toolbar": "文档", "body": [ { "type": "form", "autoFocus": false, "messages": { "validateFailed": "请仔细检查表单规则,部分表单项没通过验证" }, "title": "表单", "actions": [ { "type": "submit", "label": "提交" } ], "api": "/api/mock2/form/saveFormFailed?waitSeconds=2", "mode": "horizontal", "controls": [ { "name": "minLength", "type": "text", "label": "长度限制", "validations": "minLength:10", "validateOnChange": false } ] } ] } --- src/renderers/Form/Control.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/Form/Control.tsx b/src/renderers/Form/Control.tsx index c0ecd5d3..3f71d2ba 100644 --- a/src/renderers/Form/Control.tsx +++ b/src/renderers/Form/Control.tsx @@ -380,7 +380,7 @@ export default class FormControl extends React.PureComponent< (validateOnChange !== false && (form.submited || this.model.validated)) ) { this.lazyValidate(); - } else if (validateOnChange === false && !this.model.valid) { + } else if (validateOnChange === false) { this.model.reset(); } From 3ea958f0092490b10ed1adb052cdd530d5941755 Mon Sep 17 00:00:00 2001 From: rickcole Date: Mon, 10 Aug 2020 17:16:01 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dimage=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E8=A1=A8=E5=8D=95=E6=8F=90=E4=BA=A4loading?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Form/Image.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/renderers/Form/Image.tsx b/src/renderers/Form/Image.tsx index 6f20c8e6..f9b0e215 100644 --- a/src/renderers/Form/Image.tsx +++ b/src/renderers/Form/Image.tsx @@ -334,6 +334,7 @@ export default class ImageControl extends React.Component< startUpload(retry: boolean = false) { if (this.state.uploading) { + this.resolve && this.resolve(null); return; } From fab33f9d5b8f03e61d4a6df67300b9edca2895b4 Mon Sep 17 00:00:00 2001 From: rickcole Date: Mon, 10 Aug 2020 20:18:42 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E8=B0=83=E6=95=B4autofill=E7=9A=84?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Form/Image.tsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/renderers/Form/Image.tsx b/src/renderers/Form/Image.tsx index f9b0e215..99438b13 100644 --- a/src/renderers/Form/Image.tsx +++ b/src/renderers/Form/Image.tsx @@ -334,7 +334,6 @@ export default class ImageControl extends React.Component< startUpload(retry: boolean = false) { if (this.state.uploading) { - this.resolve && this.resolve(null); return; } @@ -370,6 +369,7 @@ export default class ImageControl extends React.Component< } tick() { + const {multiple, autoFill, onBulkChange} = this.props; if (this.current || !this.state.uploading) { return; } @@ -429,7 +429,16 @@ export default class ImageControl extends React.Component< { files: this.files = files }, - this.tick + () => { + const sendTo = + !multiple && + autoFill && + !isEmpty(autoFill) && + dataMapping(autoFill, obj || {}); + sendTo && onBulkChange(sendTo); + + this.tick(); + } ); }, progress => { @@ -778,13 +787,6 @@ export default class ImageControl extends React.Component< }; obj.value = obj.value || obj.url; - const sendTo = - !multiple && - autoFill && - !isEmpty(autoFill) && - dataMapping(autoFill, obj); - sendTo && onBulkChange(sendTo); - cb(null, file, obj); }) .catch(error => cb(error.message || __('上传失败,请重试'), file)); From 846067c05a0027b3670a0bbd39d32f15a9ddb164 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Mon, 10 Aug 2020 21:59:42 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BB=A5=E9=98=B2=E4=B8=87=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/formItem.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/store/formItem.ts b/src/store/formItem.ts index 3fa7fb19..957363a6 100644 --- a/src/store/formItem.ts +++ b/src/store/formItem.ts @@ -565,6 +565,12 @@ export const FormItemStore = types const form = self.form; const value = self.value; + + // 有可能销毁了 + if (!form) { + return; + } + const selected = Array.isArray(value) ? value.map(item => item && item.hasOwnProperty(self.valueField || 'value') From 669c80ec2bfd93c3bfec0b0aa67c0dedfbc5ed59 Mon Sep 17 00:00:00 2001 From: rickcole Date: Mon, 10 Aug 2020 23:49:39 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=A1=A5=E4=B8=80=E4=B8=8Bfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderers/Form/File.tsx | 25 ++++++++++++------------- src/renderers/Form/Image.tsx | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/renderers/Form/File.tsx b/src/renderers/Form/File.tsx index 4b535780..149b88c8 100644 --- a/src/renderers/Form/File.tsx +++ b/src/renderers/Form/File.tsx @@ -400,7 +400,7 @@ export default class FileControl extends React.Component { return; } - const __ = this.props.translate; + const {translate: __, multiple, autoFill, onBulkChange} = this.props; const file = find( this.state.files, item => item.state === 'pending' @@ -441,7 +441,16 @@ export default class FileControl extends React.Component { error: error ? error : null, files: files }, - this.tick + () => { + const sendTo = + !multiple && + autoFill && + !isEmpty(autoFill) && + dataMapping(autoFill, obj || {}); + sendTo && onBulkChange(sendTo); + + this.tick(); + } ); }, progress => { @@ -498,10 +507,7 @@ export default class FileControl extends React.Component { asBase64, asBlob, data, - translate: __, - multiple, - autoFill, - onBulkChange + translate: __ } = this.props; if (asBase64) { @@ -563,13 +569,6 @@ export default class FileControl extends React.Component { onProgress(1); const value = (ret.data as any).value || ret.data; - const sendTo = - !multiple && - autoFill && - !isEmpty(autoFill) && - dataMapping(autoFill, ret.data); - sendTo && onBulkChange(sendTo); - cb(null, file, { ...(isPlainObject(ret.data) ? ret.data : null), value: value, diff --git a/src/renderers/Form/Image.tsx b/src/renderers/Form/Image.tsx index 99438b13..0c01de36 100644 --- a/src/renderers/Form/Image.tsx +++ b/src/renderers/Form/Image.tsx @@ -774,7 +774,7 @@ export default class ImageControl extends React.Component< cb: (error: null | string, file: Blob, obj?: FileValue) => void, onProgress: (progress: number) => void ) { - const {translate: __, multiple, autoFill, onBulkChange} = this.props; + const {translate: __} = this.props; this._send(file, this.props.reciever as string, {}, onProgress) .then((ret: Payload) => { if (ret.status) { From c267b3f4a2ee373aaf80850e40eea63a2bef319b Mon Sep 17 00:00:00 2001 From: rickcole Date: Mon, 10 Aug 2020 23:53:40 +0800 Subject: [PATCH 6/6] fix --- src/renderers/Form/Image.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/Form/Image.tsx b/src/renderers/Form/Image.tsx index 0c01de36..53c59661 100644 --- a/src/renderers/Form/Image.tsx +++ b/src/renderers/Form/Image.tsx @@ -774,7 +774,7 @@ export default class ImageControl extends React.Component< cb: (error: null | string, file: Blob, obj?: FileValue) => void, onProgress: (progress: number) => void ) { - const {translate: __} = this.props; + const __ = this.props.translate; this._send(file, this.props.reciever as string, {}, onProgress) .then((ret: Payload) => { if (ret.status) {