Skip to content

Form校验异常时Error信息展示异常 #6984

@johnnyhwa

Description

@johnnyhwa
  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

1.7.8

Environment

ant-design-vue 1.7.8
moment 2.22.1
vue 2.5.17

Reproduction link

Edit on CodeSandbox

Steps to reproduce

前提

触发条件:

  • 字段2的fieldName需要包含字段1的fieldName
  • 字段2的fieldName比字段1的fieldName长
  • 字段2的fieldName超出字段1fieldName长度 1的部分必须是数字
  • 字段1配置rules,required为false;字段2配置rules,requlred为true
  • 不填写字段值,直接对form进行校验

参考

例如:

  • "1"和"111",超出部分为"1"
  • "code"和"codes2",超出部分为"2"

ant-design-vue源码问题定位

https://github.com/vueComponent/ant-design-vue/blob/1.x/components/vc-form/src/createBaseForm.jsx#L556-L568

...
// Skip if not match array type
if (
rules.every(({ type }) => type !== 'array') &&
errorFieldName.indexOf(ruleFieldName) !== 0
) {
return false;
}

// Exist if match the field name
const restPath = errorFieldName.slice(ruleFieldName.length   1);
if (/^\d $/.test(restPath)) {
fieldName = ruleFieldName;
return true;
}
...

What is expected?

点击校验后,form在字段2下方提示必填信息

What is actually happening?

点击校验后,form在字段1的下方提示了必填信息

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions