Netlify-cms: number widget saving as string with valueType int

Created on 15 Jan 2019  路  17Comments  路  Source: netlify/netlify-cms

Describe the bug

I have a field set to the number widget where it's taking an initially set integer value but saving it as a string.

To Reproduce

config.yml

collections:
  - name: product
    label: Products
    extension: yml
    format: yml
    fields:
      - name: price
        label: price
        widget: number
        valueType: int
        default: 0

document.yml

price: 264

After changing the product price to 265 through Netlify CMS, the updated document looks like:

price: '265'

Expected behavior

Save output as integer

Applicable Versions:

https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js

extensionwidgets beginner good first issue bug stale

All 17 comments

Seeing the same thing here. This causes big problems with Gatsby as it cannot infer type if there are multiple types used for the same field. I had added numbers to the fields, then someone edited a file using the CMS and this resulted in the number being saved as string, causing Gatsby to ignore the field entirely and breaking our build.

If anyone needs a short-term solution to this, you will need to coerce any fields that use the number widget to numbers and write them to a field, then use that field. Gatsby will still complain, but at least you can get moving.

I cannot reproduce this issue, @erquhart can you confirm from your end?

I'm on holiday away from my machine, but my issue is the same as @zanona's. Root level of a collection but for me it was a yaml front matter field in a markdown file.

Before save:

index:  4

After save:

Index:  '4'

@barthc Not seeing this issue any more with 2.4.1

That's awesome - @zanona can you confirm this is resolved for you in 2.4.1?

Hi, @erquhart. I'm afraid not, unfortunately :(

image

config.yml
image

@zanona You don't have a valueType set, so it will save as a sting. Add a valueType of int.

I'm afraid nothing changes, @Undistraction.
I have had it set before but disabled since it wasn't working.

image
image

Is this still an active issue? @zanona

Hi, @alishamohanty
It seems to be working now :)
That's great. Thanks so much.

image

You're Welcome @zanona :)

I suppose this ticket can be closed.

This is still an issue if the value is removed. If the field is not required and you remove a previously set number you should get null not '' or graphql will still complain about the type mismatch.

We really need to start having widgets handle setting their own empty values rather than guessing from the core.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

The empty value issue is covered under #2848.

Tracking in #995 instead.

Was this page helpful?
0 / 5 - 0 ratings