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

Support optional objects #465

Closed
2 tasks done
mfulton26 opened this issue Feb 9, 2017 · 6 comments
Closed
2 tasks done

Support optional objects #465

mfulton26 opened this issue Feb 9, 2017 · 6 comments

Comments

@mfulton26
Copy link
Contributor

Prerequisites

  • I have read the documentation;
  • In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

Add support for not specifying an optional object property.

Steps to Reproduce

  1. Define a schema with a property of type object which is not required.
  2. Render the schema on a react-jsonschema-form and attempt to not specify the optional object property.

https://jsfiddle.net/f2y3fq7L/19/

Expected behavior

Have some sort of checkbox or something to enable/disable specifying the optional object property.

Actual behavior

There is no apparent way to not specify the optional object property.

Version

0.42.0

@n1k0
Copy link
Collaborator

n1k0 commented Feb 13, 2017

Yeah, I've worked on a patch to make fields collapsible in the past but it was discarded in favor of theming; maybe we'd want to resurect it at some point, as this use case still seems valid to me.

@elisechant
Copy link
Contributor

@mfulton26 would the example from the docs work for you here? https://jsfiddle.net/69z2wepo/68259/

@mfulton26
Copy link
Contributor Author

I suppose although it does alter the schema and it seems like a lot of overhead if I have many optional objects.

@dropdevcoding
Copy link

dropdevcoding commented Apr 7, 2017

In fact the form actually also validates wrong in this case which is very annoying. When defining an optional object inside the schema which has required fields the required fields always get validated although the schema would allow the whole object not to be there. (#331)

@literarymachine
Copy link

I just had the same problem described here and in #331; a workaround seems to be to specify the property as type array with the object as its items and maxItems of 1: https://jsfiddle.net/z8b5s7t2/

wms added a commit to wms/react-jsonschema-form that referenced this issue Mar 8, 2019
Modifies the implementation of `getSchemaType` so that when a property
has a type of `[<any>, 'null']`, then `<any>` will be passed. This
allows the library to render and validate the field correctly. For the
sake of simplicity, this change does not attempt any further
assumptions, coercions or transformations.

References rjsf-team#465
epicfaace pushed a commit that referenced this issue Mar 12, 2019
* Basic support for 'nullable' types

Modifies the implementation of `getSchemaType` so that when a property
has a type of `[<any>, 'null']`, then `<any>` will be passed. This
allows the library to render and validate the field correctly. For the
sake of simplicity, this change does not attempt any further
assumptions, coercions or transformations.

References #465

* Add some test cases to `getSchemaType` spec

* Add FAQ entry detailing nullable type behaviour

* Add Playground example for nullable field

* Tweak FAQ entry wording and fix typo

Co-Authored-By: warrenseymour <warren@fountainhead.tech>

* Correct example in FAQ entry

Co-Authored-By: warrenseymour <warren@fountainhead.tech>
@epicfaace
Copy link
Member

Closing this in favor of #675

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants