Skip to content

Optional object and required field widgets #2790

@saenglert

Description

@saenglert

Describe the bug
A required widget (number in this case) that is field of an optional object widget is required despite the optional object widget receiving no input.

To Reproduce

  1. Configure optional object widget
  2. Give widget required child widgets
  3. Error: [Child Widget] is required

CMS configuration

- name: score
      label: Ergebnis
      widget: object
      required: false
      fields:
        - {name: home, label: "Punkte Heimteam", widget: number, min: 0, step: 1, valueType: int}
        - {name: away, label: "Punkte Auswärtsteam", widget: number, min: 0, step: 1, valueType: int}

Expected behavior
The required child widgets should only be required if the optional parent receives data since undefined is a valid value for the parent.

I think the best analogy for this is using TypeScript . Consider the following type:

type score = {home: number, away: number} | undefined;

score may be undefined (the match hasn't been played yet) or an object that must contain a home and away field of type number.

On the surface a quick solution would be to make the child widgets optional as well however in that case a user could input only one of two parts of the score (Home 10 : 'undefined' Away) which would be an invalid input.

Applicable Versions:

  • Netlify CMS version: 2.9.7
  • Git provider: GitHub
  • OS: Win 10
  • Browser version: Firefox 69.0.3
  • Node.JS version: 10.15.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions