decaporg / decaporg/decap-cms

'boolean' widget without default value behaves strangely

Open
#1,424 11 comments 9 reactions 0 assignees View on GitHub
area: extensions/widgets exp: beginner kind: bug pinned status: confirmed
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

**- Do you want to request a *feature* or report a *bug*?**

*bug*

**- What is the current behavior?**

A `boolean` field without a `default` defined in config.yml will initially render as `false`, but the field will fail the required check:

![screen shot 2018-06-11 at 16 56 36](https://user-images.githubusercontent.com/373545/41241378-0e83777a-6d9d-11e8-9743-1c54fce64abd.png)

Clicking the widget twice so it turns on and back off allows me to persist a value of `false`.

**- If the current behavior is a bug, please provide the steps to reproduce.**

1. Define a field like this in config.yml:

```yaml
-
label: Awesome
name: awesome
widget: boolean
```

2. Create a new item in the collection
3. Try to publish the item

You'll get an "AWESOME IS REQUIRED" error.

For the record, specifying `default: false` for the field makes the problem disappear.

Because [`default` presently doesn't work for editor components](https://github.com/netlify/netlify-cms/issues/1406), this problem makes it hard to get the `boolean` widget working in that setting.

**- What is the expected behavior?**

That the error does not show and `awesome: false` gets persisted. Or that an error is thrown early because the field doesn't have a `default` specified. Alternatively that a distinct "undefined" state be added for boolean fields so that you could at least tell the difference between "off" and "undefined".

**- Please mention your versions where applicable.**

Netlify CMS version: 1.8.4
Browser version: 67.0.3396.62/OSX

Node.JS version: 9.5.0
Operating System: Mac OSX 10.13.4 (High Sierra)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.