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 4 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

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?

rohansaw avatar Jul 03 '23 12:07 rohansaw

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.

stale[bot] avatar Oct 02 '24 00:10 stale[bot]

This issue was closed because of lack of recent activity. Reopen if you still need assistance.

stale[bot] avatar Nov 04 '24 00:11 stale[bot]