decaporg / decaporg/decap-cms

Number widget with float value type appears to be truncated

Open
#4,808 3 comments 2 reactions 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

Given that I have a `number` widget defined with a value type of `float`, as below:

```yaml
- {
label: "Opacity",
name: "overlay_filter",
widget: "number",
value_type: "float",
min: 0.0,
max: 1.0,
step: 0.1,
default: 0.5,
}
```

Expected behavior:

* Should display `0.5` by default
* Clicking down arrow in the UI from the default should change value to `0.4`
* Clicking ui arrow in the UI should change value to `0.6`
* I shouldn't be able to increment past `1.0`
* I shouldn't be able to decrement past `0.0`

Actual behavior:

* Previously saved value of `0.5` loads
* Clicking down arrow from default changes value to `0`
* Clicking up arrow from default changes value to `0`
* I am unable to increment or decrement in any way beyond 0
* Directly entering a value, e.g `0.3`, causes it to revert to 0.

The strange thing is, it appears that the HTML is rendered as I'd expect:

```html

```

If I look at Redux in my dev tools, it appears there's a `DRAFT_CHANGE_FIELD` event that is saying the field has been set to 0.

I think it might be possible that there's a bug in some onchange logic with the number fields that are causing floats to be truncated and thus the `0` to persist (truncated vs rounded as 0.9 goes back to 0 as well.)

**Applicable Versions:**

- netlify-cms-app 2.12.13
- netlify-cms-core 2.27.0
- netlify-cms 2.10.49
- Git provider: GitHub
- OS: Win 10 20H2 (19042.685)
- Browser version: Chrome 87.0, Firefox 84.0.1

**CMS configuration**

```yaml
- {
label: "Opacity",
name: "overlay_filter",
widget: "number",
value_type: "float",
min: 0.0,
max: 1.0,
step: 0.1,
default: 0.5,
}
```

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.