Fix parsing of numbers when assigning a default value to a number field

This commit is contained in:
Andrew Kingston 2021-08-04 14:38:20 +01:00
parent eaaee33906
commit c0ca68cb83
1 changed files with 8 additions and 1 deletions

View File

@ -2,10 +2,17 @@
import StringField from "./StringField.svelte" import StringField from "./StringField.svelte"
export let defaultValue export let defaultValue
const parseNumber = val => {
if (val == null) {
return null
}
return isNaN(val) ? null : parseFloat(val)
}
</script> </script>
<StringField <StringField
{...$$props} {...$$props}
type="number" type="number"
defaultValue={isNaN(defaultValue) ? null : parseFloat(defaultValue)} defaultValue={parseNumber(defaultValue)}
/> />