rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
14.25k stars 2.18k forks source link

Default Enum Values in OneOf Definitions do not appear in form data submissions #2296

Open AScully24 opened 3 years ago

AScully24 commented 3 years ago

Prerequisites

Description

When submitting an enum value from a field contained in a oneOf definition, the default value is not included in the formData property after submission.

JS Fiddle Example

Playground

Steps to Reproduce

  1. Use the following schema in the Playground / JS Fiddle:
    {
    "title": "OneOf Enum Bug",
    "type": "object",
    "additionalProperties": false,
    "properties": {
    "Name": {
      "type": "string"
    },
    "one-of-example-field": {
      "oneOf": [
        {
          "$ref": "#/definitions/MyDefinition",
          "title": "My Choice"
        }
      ]
    }
    },
    "required": [
    "Name"
    ],
    "definitions": {
    "MyDefinition": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "this default enum will not be in the submitted form data": {
          "type": "string",
          "enum": [
            "foo-bar"
          ],
          "default": "foo-bar"
        },
        "Header Key": {
          "type": "string"
        },
        "Header Value": {
          "type": "string"
        }
      },
      "required": []
    }
    }
    }
  2. Fill in any fields
  3. Submit the form

Expected behavior

Form data should contain all fields, including the default enum value described in MyDefinition

Actual behavior

The default value is not present

Version

2.5.1

rohansaw commented 1 year ago

I also encountered the issue as described above - in addition, the default value of "oneOf" fileds are not rendered in the form. Is there any fix planned for this, since this issue has been open for more than 2 years?

stale[bot] commented 1 week ago

This issue has been automatically marked as possibly close because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.