fix: validateOnChange=false时,提交后修改内容,表单不校验

当配置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": "<a target='_blank' href='/docs/renderers/Form/FormItem'>文档</a>",
    "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
                }
            ]
        }
    ]
}
This commit is contained in:
DuLinRain 2020-08-08 21:57:21 +08:00 committed by GitHub
parent f7c2e14c6d
commit b9b1f539bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -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();
}