Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

number widget saving as string with valueType int #2007

Closed
zanona opened this issue Jan 15, 2019 · 17 comments
Closed

number widget saving as string with valueType int #2007

zanona opened this issue Jan 15, 2019 · 17 comments

Comments

@zanona
Copy link

zanona commented Jan 15, 2019

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

@Undistraction
Copy link
Contributor

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.

@barthc
Copy link
Contributor

barthc commented Feb 3, 2019

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

@Undistraction
Copy link
Contributor

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'

@Undistraction
Copy link
Contributor

Undistraction commented Feb 11, 2019

@barthc Not seeing this issue any more with 2.4.1

@erquhart
Copy link
Contributor

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

@zanona
Copy link
Author

zanona commented Feb 12, 2019

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

image

config.yml
image

@Undistraction
Copy link
Contributor

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

@zanona
Copy link
Author

zanona commented Feb 12, 2019

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

image
image

@alishamohanty
Copy link

Is this still an active issue? @zanona

@zanona
Copy link
Author

zanona commented Apr 23, 2019

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

image

@alishamohanty
Copy link

You're Welcome @zanona :)

@alishamohanty
Copy link

I suppose this ticket can be closed.

@abstracthat
Copy link

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.

abstracthat added a commit to abstracthat/netlify-cms that referenced this issue Apr 24, 2019
abstracthat added a commit to abstracthat/netlify-cms that referenced this issue Apr 24, 2019
abstracthat added a commit to abstracthat/netlify-cms that referenced this issue Apr 24, 2019
@erquhart
Copy link
Contributor

erquhart commented May 9, 2019

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

@stale
Copy link

stale bot commented Oct 29, 2019

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.

@erquhart
Copy link
Contributor

The empty value issue is covered under #2848.

@erquhart
Copy link
Contributor

Tracking in #995 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants