-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Description
Describe the bug
When using widget: "number, required: false
, if you:
- Working correctly: Leave the field blank and publish the item, the
yaml
file will not include the field name under the item. For example, if the field name isfoo
and there is anotherbar
field that is required, the yaml file will be:
item:
- bar: 7
- Working correctly: Enter a number to the field and republish the item, the
yaml
file will include the field with the correct value. For example:
item
- bar: 7
- foo: 3
- NOT WORKING CORRECTLY: Complete step 2 above, then go back to the item and delete the number from the field then republish the item, the
yaml
file will include the field with an empty string as it's value. For example:
item
- bar: 7
- foo: ''
This causes issues when using GraphQL as:
-
The schema type cannot be inferred. In situation 1 above, there is no
foo
field so attempting to queryfoo
will result in an error. This means schema type must be explicitly set. -
You can't explicitly set the schema type for
foo
as it can be eitherString
orInt
, and GraphQL doesn't support union scalar types.
To Reproduce
Create a field with widget: "number", required: false
then run through the three situations above.
Expected behavior
If no number is entered then it should either leave the field out of the yaml
file, or define the value as null
.
Applicable Versions:
- Netlify CMS version: "netlify-cms-app": "^2.9.7"
- Git provider: File system ("gatsby-source-filesystem": "^2.1.33")
- OS: Windows 10
- Browser version: Chrome Version 78.0.3904.87 (Official Build) (64-bit)
- Node.JS version: v10.15.3
CMS configuration
Relevant sections only:
const config = {
load_config_file: false,
media_folder: "static/img",
public_folder: "img",
collections: [
{
label: "Settings",
name: "settings",
delete: false,
editor: {
preview: false
},
files: [
{
label: "Typography",
name: "typography",
file: `${__dirname}/data/typography/typography.yaml`,
fields: [
{
label: "Titles (H1)",
name: "h1",
widget: "object",
fields: [
{
label: "Font",
name: "fontFamily",
widget: "string"
},
{
label: "Size",
name: "size",
required: false,
widget: "number"
}
]
}
]
}
]
},
]
};
Metadata
Metadata
Assignees
Labels
No labels