react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Cannot check for existing errors on field in CustomValidate

Open TheOneTheOnlyJJ opened this issue 5 months ago • 4 comments

Prerequisites

What theme are you using?

core

Version

5.20.0

Current Behavior

I have a username field in my form that I want to invalidate if it is not unique. I check its uniqueness with an API call, which always runs in my CustomValidate function. However, it would be more efficient only to run it if there are no other prior errors on that field (I have a pattern in the JSON schema that disallows certain characters). I am trying to do a simple if based on the errors.username.__errors variable, but no matter in which configuration I write the condition, I can only get it to always be true or never be true, regardless of the presence of other errors.

Expected Behavior

I expect a check such as if (!errors.username.__errors || errors.username.__errors.length === 0) to be true if there are no errors associated to the username field, and false if there is at least one.

Steps To Reproduce

No response

Environment

- OS: Windows 10
- Node: 20.15.0
- npm: 10.8.2

Anything else?

No response

TheOneTheOnlyJJ avatar Aug 30 '24 16:08 TheOneTheOnlyJJ