Skip to content

Custom validation error doesn't hide on good result #4365

@shishmak

Description

@shishmak

Prerequisites

What theme are you using?

utils

Version

5.x

Current Behavior

Hello,
I need to have custom validation depense with 2 fields
Previosly I use rjsf 3.x and all works good. I upgrade project to 5.x and find bug (as I think).

I have a form with a dependency "Test" <= "Test2". I applied a custom validation where I specified this dependency.
const validate = (formData: any, errors: FormValidation) => { if (formData["Test"] > formData["Test2"]) errors["Test"]?.addError("Test should be LE than Test2"); return errors; };
And I noticed a problem:
Let's say initially I have Test = 10 and Test2 = 15
image
If I set Test2 = 5, then an error will appear near Test. This is the correct behavior
image
If I return Test2 = 15, then the error will not disappear. And this looks like a bug, because the values ​​​​Test (10) and Test2 (15) satisfy the condition "Test" <= "Test2"
image

example of my code:
https://codesandbox.io/p/sandbox/yyrxsp

Expected Behavior

If no validation errors are found, then no errors should be shown.

This error should not be there,
image

because according to the code the condition = false
const validate = (formData: any, errors: FormValidation) => { if (formData["Test"] > formData["Test2"]) errors["Test"]?.addError("Test should be LE than Test2"); return errors; };
Test < Test2 (10 < 15)

Steps To Reproduce

https://codesandbox.io/p/sandbox/yyrxsp

  1. set Test 2 = 5 (an error will appear near "Test 1")
  2. set Test 2 = 15 (the error near "Test 1" will not disappear)

Environment

- OS: windows 10
- Node: v20.11.0
- npm: 10.3.0

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions