A few statements about default behavior that we may want to pin down so we know how we'd like to proceed as the extending Tina work progresses.
When in edit-mode, null values are replaced with their default items*
*not working yet, but will - would like to get an idea for expectations before implementing.
This is currently considered a feature, but I'm not sure it's what we want. As an editor, you may land on a page and see exactly what you want (because the developer set up good default values. So you don't save anything or really do anything, and you never exit edit-mode. At that point, when your work goes to production there will be a missing value.
Outermost defaultValue
wins
defineSchema({
collections: [
{
label: 'Block Page',
name: 'blockPage',
format: 'mdx',
path: 'content/block-pages',
fields: [
{
label: 'Blocks',
name: 'blocks',
type: 'object',
list: true,
ui: {
defaultValue: [{
_template: 'hero',
title: "hello #1"
}]
},
templates: [
{
name: 'hero',
label: 'Hero',
ui: {
defaultValue: {
title: 'hello #2',
},
},
fields: [
{
label: 'Title',
name: 'title',
type: 'string',
},
{
label: 'Description',
name: 'description',
type: 'string',
},
],
},
],
},
],
},
],
})
The value will be:
[{
_template: 'hero',
title: "hello #1"
}]
Instead of
[{
_template: 'hero',
title: "hello #2"
}]
What should the behavior be is open for interpretation, though some have mentioned this feels wrong and the most-specific property should win.
Similarly, defaultItem
on a list object ignores child default values
What is the expected behavior here?
defaultValue
is not used if an adjacent field is present
AKA - we don't merge real/default values.
If I have a title
field and a description
field.
{
label: 'Title',
name: 'title',
type: 'string',
ui: {
defaultValue: 'Some title',
},
},
{
label: 'Description',
name: 'description',
type: 'string',
ui: {
defaultValue: 'Some description',
},
},
And a document with only the title
:
---
title: "Hello, World"
---
The form.values
will be {title: "Hello, World"}
question