react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

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

Open AScully24 opened this issue 3 years ago • 2 comments

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": []
    }
  }
}
  1. Fill in any fields
  2. 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

AScully24 avatar Mar 22 '21 10:03 AScully24