ajv-validator / ajv-validator/ajv-errors

Required Keyword Error Message - Error is raised at incorrect level

未关闭
#148 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
289
派生
21
PR 合并指标
30 天内没有已合并 PR

描述

Hi,

I came across something strange when using ajv and ajv errors along with react hook form.

Codesandbox -> https://codesandbox.io/s/epic-golick-q7opzj

Steps to reproduce:
1) Click in and out of the account number to see the errors being printed to the console.
2) Toggle the errorMessage within account_detail (lines 40-42) to see the difference in behaviour on how the errors are raised.

**errorMessage at root level**
You can see in this image the error is raised at the root level (account_details) with the overridden required error message as specified in the errorMessage on the schema.
image

**errorMessage at root level is commented out**
You can see in this image the error is raised at the lowest possible level (the property itself account_details.account_type) with the standard required error message from ajv.
image

Is this behaviour intended? It makes it difficult to override the errorMessage for 'required' fields and correlate them to the correct property on the schema given that they are being raised at the root level.

Looking forward to hearing from you.

Thanks
James

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。