decaporg / decaporg/decap-cms

Nested non-required object validation does not work

Open
#2,103 15 comments 11 reactions 0 assignees View on GitHub
pinned
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

**Describe the bug**

When an non-required object inside an object has required fields, the object widgets validation ignores the non-required attribute of the object and highlights the required sub fields of the non-required object as required.

**To Reproduce**

1. Use configuration below
1. Create New Something
1. Only fill title string

**Expected behavior**

Entry saved correctly because `some-metadata-property` is not required.

**Current behavior**

Entry is not saved and `property-specific-string` is shown as required.

**Screenshots**

![output](https://user-images.githubusercontent.com/848854/52915928-2f56fc80-32da-11e9-9dcd-6fca6219fb51.gif)

**Applicable Versions:**

- Netlify CMS version: 2.4.2

**CMS configuration**
```
backend:
name: test-repo
media_folder: assets
collections: # A list of collections the CMS should be able to edit
- name: something
label: 'Something'
folder: nested
create: true
fields:
- name: title
widget: string
- name: metadata
widget: object
fields:
- name: some-metadata-property
widget: object
required: false
fields:
- name: property-specific-string
widget: string
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the YAML configuration and title-only entry described in the report, then trace validation for nested object widgets. Done means an optional nested object does not require its child fields and the entry saves successfully when only the title is filled.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.