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

"Omit extra items" does not omit arrays in dependencies #1357

Open
3 tasks done
epicfaace opened this issue Jul 13, 2019 · 1 comment
Open
3 tasks done

"Omit extra items" does not omit arrays in dependencies #1357

epicfaace opened this issue Jul 13, 2019 · 1 comment

Comments

@epicfaace
Copy link
Member

Prerequisites

Description

Playground link

Steps to Reproduce

  1. Check "Omit extra data" and "Live omit"
  2. Click on "opt" to make it true
  3. Check "a" and "b"
  4. Click "opt" to make it false
  5. Check "b" and "d"

Expected behavior

When clicking "opt" to make it false, "a" and "b" should be omitted from the form data. I should end up with the form data's value of "arr" to equal ["c", "d"].

Actual behavior

"a" and "b" is not omitted from the form data. I end up with the form data's value of "arr" to equal ["a", "b", "c", "d"].

Version

1.6.1

@Fakhri1989
Copy link

Fakhri1989 commented Aug 26, 2021

@epicfaace I need to ask a question about a snippet of code that seems to be causing this,
while trying to work on this (not updating the FORM DATA properly when updating the values in the form) we noticed that the issue occurs only when we have both omit extra data and live omit both checked, this has only one consequence in the entire codebase (only one condition is dependant on both these flags at the same time) which is in
react-jsonschema-form>packages>code>src>component>form.js :

if (this.props.omitExtraData === true && this.props.liveOmit === true) {
      const retrievedSchema = retrieveSchema(
        this.state.schema,
        this.state.schema,
        formData
      );

      const pathSchema = toPathSchema(
        retrievedSchema,
        "",
        this.state.schema,
        formData
      );

      const fieldNames = this.getFieldNames(pathSchema, formData);
      newFormData = this.getUsedFormData(formData, fieldNames);

      state = {
        formData: newFormData,
      };

commenting this condition seems to solve the problem (at least superficially), now to my question, what is the purpose of this condition?

in the code you mentioned the following:
If omitExtraData and liveOmit are both set to true, then extra form data values that are not in any form field will be removed whenever onChange is called. Set to false by default.

commenting out this condition seemed to resolve both the issue mentioned above and adding arrays to the formData.

other related issues:
https://github.com/rjsf-team/react-jsonschema-form/issues/1671
https://github.com/rjsf-team/react-jsonschema-form/pull/1564

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

5 participants