rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
14.38k stars 2.2k forks source link

Error not propagated when raising errors from a custom widget or field #4382

Closed guilhermecastros closed 1 week ago

guilhermecastros commented 2 weeks ago

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

Error messages are not being propagated correctly for json object schemas.

For instance I have these two schemas, when I raise a custom error with schema2 it works nice as expected & described on the documentation. But when I do the same, but for schema which has a type object it doesn't work.

export const schema: RJSFSchema = {
  properties: {
    Test: {
      type: "number",
      title: "Test 1",
    },
    Test2: {
      type: "number",
      title: "Test 2",
    },
  },
  type: "object",
};
export const schema2: RJSFSchema = {
  type: "string",
  default: "hello",
};

I have created the following playground that allows you to play & to check the current behavior ⬇️

https://codesandbox.io/p/sandbox/rjsf-custom-error-ql66mh?workspaceId=7d9d1079-911b-4954-9a3d-7c3de5279f0c

image

image

Expected Behavior

Custom errors should show regardless of the schema used, which means it should show on both described scenarios.

Steps To Reproduce

  1. Open playground.
  2. You will see that I am rendering two schemas.
  3. Type something on each field
  4. You will see that for the schema of type object, no error is shown.

Environment

- OS:
- Node:
- npm:

Anything else?

No response

guilhermecastros commented 1 week ago

I believe this issue is related to https://github.com/rjsf-team/react-jsonschema-form/pull/4188. Maybe @abdalla-rko knows more about this?

heath-freenome commented 1 week ago

@guilhermecastros Thanks for finding this. We have a bug in our NumberField which I will be fixing soon