decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

'boolean' widget without default value behaves strangely

Open papandreou opened this issue 7 years ago • 11 comments

- 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

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:
-
  label: Awesome
  name: awesome
  widget: boolean
  1. Create a new item in the collection
  2. 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, 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)

papandreou avatar Jun 11 '18 15:06 papandreou

@erquhart/ @papandreou is this issue still valid? It's open but it looks like a fix was merged for widgets. Just looking for an issue to help out with :)

TatisLois avatar Jan 04 '19 21:01 TatisLois

@TatisLois, I can still reproduce it with [email protected]. Which fix is that?

papandreou avatar Jan 04 '19 21:01 papandreou

#1662 was never merged, that's probably why it didn't have an effect :laughing:

papandreou avatar Jan 04 '19 21:01 papandreou

@TatisLois If you are still up for this, I can guide you on how to implement a simple fix for this issue.

barthc avatar Jan 06 '19 22:01 barthc

@barthc that would be great, would love to take a crack at it

TatisLois avatar Jan 15 '19 17:01 TatisLois

@TatisLois take a look at the createEmptyDraftData function, just check for boolean widgets that does not have any default value and assign a false value, that's it. Also add some comments to explain the assigment. You can DM me on gitter if you have any questions :+1:

barthc avatar Jan 16 '19 21:01 barthc

I opened a PR in https://github.com/netlify/netlify-cms/pull/2525. Reviews are welcome 😊

chrfritsch avatar Aug 08 '19 20:08 chrfritsch

This should be resolved when #1407 is resolved. Leaving open until then.

erquhart avatar Oct 24 '19 19:10 erquhart

Specifying a false default as in - {label: "Noindex", name: "no_index", widget: "boolean", default: false} does not work for me. I am still forced to click twice on the toggle to make it falsy.

belmarca avatar Sep 22 '20 19:09 belmarca

@erquhart Any update on this? I'm having the same problem that @belmarca has.

miguelt1 avatar Jul 14 '21 09:07 miguelt1

Hi @miguelt1, the best way to move this issue forward is to submit a contribution for it

erezrokah avatar Jul 14 '21 09:07 erezrokah