Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested properties validation #3391

Closed
3 of 4 tasks
jv00 opened this issue Jan 20, 2023 · 1 comment · Fixed by #3408
Closed
3 of 4 tasks

Nested properties validation #3391

jv00 opened this issue Jan 20, 2023 · 1 comment · Fixed by #3408

Comments

@jv00
Copy link

jv00 commented Jan 20, 2023

Prerequisites

What theme are you using?

core

Version

5.0.0-beta.15

Current Behavior

With v4, the schema used to validate nested properties inside of dependencies (e.g. oneOf) where the fields had no interaction. We have recently used v5 and in our example we have address which has several required properties such as "Town", on submit, "Town" would get validated, however in newer version (v.5) only address as a whole is validated, that is until one of the properties are set.

Expected Behavior

I went through the documentation and can't find any material on this. I have inspected v4 and in the schema example, address would be sent to {} where as in v5 address is not set to anything

Steps To Reproduce

  1. Using rjfs playground

  2. Setting schema to:

{ "type":"object", "required":[ "haveAddress" ], "properties":{ "haveAddress":{ "type":"boolean", "title":"Do you have an address?" } }, "dependencies":{ "haveAddress":{ "oneOf":[ { "required":[ "haveAddress", "address" ], "properties":{ "address":{ "type":"object", "title":"What is your home address", "required":[ "addressOne", "town", "postcode" ], "properties":{ "town":{ "type":"string", "title":"Town / City" }, "country":{ "type":"string", "title":"Country" }, "postcode":{ "type":"string", "title":"Postcode" }, "addressOne":{ "type":"string", "title":"Address 1" }, "addressTwo":{ "type":"string", "title":"Address 2" } } }, "haveAddress":{ "enum":[ true ], "type":"boolean" } } } ] } } }

  1. Check "Do you have an address?"
  2. Hit "Submit"
  3. Notice only "address" property as a whole is validated, rather than individual nested properties.

Using similar schema, which has default value set for "Town", will validate nested properties, somewhat as you would expect it to happen by default.

{ "type":"object", "required":[ "haveAddress" ], "properties":{ "haveAddress":{ "type":"boolean", "title":"Do you have an address?" } }, "dependencies":{ "haveAddress":{ "oneOf":[ { "required":[ "haveAddress", "address" ], "properties":{ "address":{ "type":"object", "title":"What is your home address", "required":[ "addressOne", "town", "postcode" ], "properties":{ "town":{ "type":"string", "title":"Town / City", "default":null }, "country":{ "type":"string", "title":"Country" }, "postcode":{ "type":"string", "title":"Postcode" }, "addressOne":{ "type":"string", "title":"Address 1" }, "addressTwo":{ "type":"string", "title":"Address 2" } } }, "haveAddress":{ "enum":[ true ], "type":"boolean" } } } ] } } }

Environment

- OS:
- Node:
- npm:

Anything else?

No response

@jv00 jv00 added bug needs triage Initial label given, to be assigned correct labels and assigned labels Jan 20, 2023
@nickgros
Copy link
Contributor

Duplicate of #3305

@nickgros nickgros marked this as a duplicate of #3305 Jan 27, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 27, 2023
Fixes rjsf-team#3391 by adding the `excludeObjectChildren` third parameter to the main `getDefaultFormState()`
@heath-freenome heath-freenome added defaults and removed needs triage Initial label given, to be assigned correct labels and assigned labels Jan 27, 2023
heath-freenome added a commit that referenced this issue Jan 27, 2023
* fix: Fix 3391 by restoring creation of empty root objects
Fixes #3391 by adding the `excludeObjectChildren` third parameter to the main `getDefaultFormState()`

* - Fixes #3393 by properly deduplicating when `schema.default` exists in `schema.examples`

* - Fix security warning to add newer versions and to unsupport old ones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants