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

Unable to input formData for oneOf while omitExtraData and liveOmit is set to true #2262

Closed
3 tasks done
maksymt1 opened this issue Mar 3, 2021 · 5 comments · Fixed by #3399
Closed
3 tasks done

Comments

@maksymt1
Copy link

maksymt1 commented Mar 3, 2021

Prerequisites

Description

Unable to input formData for oneOf while omitExtraData and liveOmit is set to true
ex: https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6e30sInNjaGVtYSI6eyJ0eXBlIjoib2JqZWN0Iiwib25lT2YiOlt7InByb3BlcnRpZXMiOnsibG9yZW0iOnsidHlwZSI6InN0cmluZyJ9fSwicmVxdWlyZWQiOlsibG9yZW0iXX0seyJwcm9wZXJ0aWVzIjp7Imlwc3VtIjp7InR5cGUiOiJzdHJpbmcifX0sInJlcXVpcmVkIjpbImlwc3VtIl19XX0sInVpU2NoZW1hIjp7fSwidGhlbWUiOiJkZWZhdWx0IiwibGl2ZVNldHRpbmdzIjp7InZhbGlkYXRlIjpmYWxzZSwiZGlzYWJsZSI6ZmFsc2UsIm9taXRFeHRyYURhdGEiOnRydWUsImxpdmVPbWl0Ijp0cnVlfX0=

Steps to Reproduce

  1. Select oneOf schema example
  2. Select omitExtraData and liveOmit
  3. Attempt to input data

Expected behavior

Data is inputted

Actual behavior

Nothing happens

Version

2.4.2

@NixBiks
Copy link
Contributor

NixBiks commented Mar 11, 2021

Same here... Which is a problem since shared fields are not resetting with anyOf/oneOf without this option. See #1819

@maksymt1
Copy link
Author

The problem seems to be coming from here:
const fieldNames = this.getFieldNames(pathSchema, formData);
or
newFormData = this.getUsedFormData(formData, fieldNames);

fieldNames is [] and let data = _pick(formData, fields); in getUsedFormData returns []

It looks like changing
if (fields.length === 0 && typeof formData !== "object") { return formData; }
to
if (fields.length === 0) { return formData; }
in getUsedFormData works but i haven't been able to test this out properly as I'm not sure about the functionality of the code/original purpose and unfortunately i haven't had the time to dig in more.

@maksymt1
Copy link
Author

maksymt1 commented Mar 22, 2021

Looking into it more it looks like the

-toPathSchema() ignores the properties contained in oneOf
-because of this fieldNames doesn’t load the names in oneOf

-and getUsedFormData() filters out the required fields

@xyy7260
Copy link

xyy7260 commented May 20, 2021

@maksymt1 hi, Do you use omitextradata and liveomit to delete extra form data values that are not in the form fields?

@knjoeyn
Copy link

knjoeyn commented Jun 30, 2021

Hi @xyy7260 we are hitting this issue as well and yes, we are using omitextradata and liveomit to delete extra form data values that are not in the form fields.

heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 25, 2023
Fixes: rjsf-team#2262
- Updated `@rjsf/utils` to update the `toPathSchema()` method to pick the closest matching option for `oneOf`/`anyOf` choices to render a path schema for it
  - Updated test to maintain 100% coverage
- Updated `@rjsf/core` to cache retrieved options in state for use in the rest of the component
  - Also improved enumOptions to output better labels for options without them when a title is available in either the `schema` or `uiSchema`
  - Added tests to validate both fixes
- Updated the `CHANGELOG.md` accordingly
heath-freenome added a commit that referenced this issue Jan 25, 2023
* fix: Reimplement 2548 to fix 2262
Fixes: #2262
- Updated `@rjsf/utils` to update the `toPathSchema()` method to pick the closest matching option for `oneOf`/`anyOf` choices to render a path schema for it
  - Updated test to maintain 100% coverage
- Updated `@rjsf/core` to cache retrieved options in state for use in the rest of the component
  - Also improved enumOptions to output better labels for options without them when a title is available in either the `schema` or `uiSchema`
  - Added tests to validate both fixes
- Updated the `CHANGELOG.md` accordingly

* Apply suggestions from code review

- Accepted reviewer suggestions

Co-authored-by: Nick Grosenbacher <nickgrosenbacher@gmail.com>

Co-authored-by: Nick Grosenbacher <nickgrosenbacher@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants