-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
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
- Configure optional object widget
- Give widget required child widgets
- 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