From 1dde199f0348070cf53f19fd19791a57bf1ff901 Mon Sep 17 00:00:00 2001 From: DuLinRain Date: Sat, 8 Aug 2020 21:57:21 +0800 Subject: [PATCH] =?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 c0ecd5d32..3f71d2ba4 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(); }