sveltia / sveltia-cms

Alternative to Netlify/Decap CMS. Fast, lightweight, Git-based headless CMS. Modern UX, first-class i18n support, open source & free. Made with Svelte.
MIT License
819 stars 38 forks source link

Float gets truncated in widget "number" #181

Closed henriksommerfeld closed 1 month ago

henriksommerfeld commented 1 month ago

I have a field defined like this in my config.yml:

{
  label: 'Mängd',
  name: 'ingredientamount',
  widget: 'number',
  valueType: 'float',
  min: 0,
  hint: 'Ange 0 om du inte vill visa någon mängd, ex. "salt"'
},

When a value is set to 1.5 in markdown, it is parsed and presented as 1 in the editor. Even if I enter 1.5 again in the editor, it writes 1 back to the markdown file. This config file is migrated from NetlifyCMS, but I don't see a reason for floats to be truncated to ints, right?

I'm using the latest version through https://unpkg.com/@sveltia/cms/dist/sveltia-cms.js.

kyoshino commented 1 month ago

Will check!

kyoshino commented 1 month ago

Looks like your config has an error: valueType (camel case) has to be value_type (snake case) as per the Number widget doc. For some reason, the properties for the Color widget are camel case, but otherwise property names in the config are always snake case 😉

valueType: 'float', # Replace the property name with value_type