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

Additional properties are not submitted when nested and omit data enabled #1497

Closed
hutch120 opened this issue Oct 31, 2019 · 5 comments · Fixed by #1774
Closed

Additional properties are not submitted when nested and omit data enabled #1497

hutch120 opened this issue Oct 31, 2019 · 5 comments · Fixed by #1774
Assignees
Labels

Comments

@hutch120
Copy link

hutch120 commented Oct 31, 2019

Prerequisites

Description

Additional properties are not submitted when nested and omit data enabled. This only happens when it is nested.

Steps to Reproduce

  1. Goto Playground example
  2. Open console so you can see submit data when you click submit button.
  3. Enable Omit extra data checkbox
  4. Add an additional property (click plus button)
  5. Click submit
  6. Check submitted formData in console ... it is empty (why?)

Expected behavior

Additional Properties submitted in form data.

Actual behavior

Nothing submitted.

Version

Used online playground version.

image

@epicfaace epicfaace added the bug label Nov 12, 2019
@epicfaace
Copy link
Member

@CodeGains any thoughts on why this might be happening?

@achendrick
Copy link

@hutch120 did you ever find a workaround for this?

I'm having what I believe is the same issue as you can see with this Playground Link.

I've traced it down to this line https://github.com/rjsf-team/react-jsonschema-form/blob/master/packages/core/src/components/Form.js#L164
Given when adding a new entry to an object it comes in with default, and of course if my form pre-populates with many entries for this field, the _isEmpty check at this line will never pass and the accumulator won't end up with this field.

#1419 introduced this line and may be worth looking at further.

If there is an alternative approach to have a key/value field in a form with JSON Schema I'd be happy to go that route instead but this is the only one I've seen (this is new to me).

@epicfaace
Copy link
Member

epicfaace commented May 13, 2020

here's a test I was writing for this:

    it.only("should rename formData key if key input is renamed in a nested object with omitExtraData=true and liveOmit=true", () => {
      const { node, onChange } = createFormComponent({
        schema: {
          type: "object",
          properties: {
            nested: {
              additionalProperties: { type: "string" }
            }
          }
        },
        formData: { nested: { key1: "value" } }
      }, {omitExtraData: true, liveOmit: true});

      const textNode = node.querySelector("#root_key1-key");
      Simulate.blur(textNode, {
        target: { value: "key1new" },
      });

      sinon.assert.calledWithMatch(onChange.lastCall, {
        formData: { nested: { key1new: "value" } }
      });
    });

@hutch120
Copy link
Author

@achendrick Hi. so we applied this to a bunch of existing JSON configuration files and the config would not fit the schema correctly without using nested additional properties. So the workaround was to leave omitExtraData set to false. This is a shame because it means our saved configs are quite messy because when we do migrations, etc, they retain the old data. Anyway, it worked, so we left it. I'd be keen to revisit/test an update if it was available.

epicfaace added a commit that referenced this issue Jul 6, 2020
Fix bug where additional properties are not submitted when nested and omit data enabled
Fixes #1497

Co-authored-by: Ashwin Ramaswami <[email protected]>
@saswat3115
Copy link

Please re check this fix. as when we implment if-else-then in rjsf few issues arising on additionalProperties + liveOmit

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

Successfully merging a pull request may close this issue.

4 participants