Closed gabrielmaldi closed 1 year ago
Sure, set an initialValue
on the field:
https://www.sanity.io/docs/initial-value-templates
Surely I'm missing something, but using:
defineField({
name: 'name',
type: 'internationalizedArrayString',
title: 'Name',
initialValue: [{_key: 'en', value: 'hello'}],
})
renders:
I'm also stuck with this issue. The docs do not suggest how make this work
Ah of course.
_key
's and _id
's can't be set with initial values in schema. Will report back with a solution.
(in the mean time it does work at the document-level!)
export default defineType({
name: 'post',
title: 'Post',
type: 'document',
initialValue: {
"strings": [
{
"_type": "internationalizedArrayStringValue",
"_key": "en",
"value": 'hello'
},
{
"_type": "internationalizedArrayStringValue",
"_key": "fr",
"value": 'bonjour'
}
]
},
fields: [
defineField({
name: 'strings',
description: 'Internationalized array of STRING',
type: 'internationalizedArrayString',
}),
]
})
Great! Just to be clear: my intention is to spare the user of having to click on EN
on each field, i.e. have every internationalized input pre-rendered for English but without a value. Maybe as a workaround value: ""
can be used (and that'd be fine with me), but a nicer solution would be to perhaps set defaultLanguage: "en"
at the document level and have the plugin do the heavy lifting behind the scenes.
Thank you!
Version 1.7.0 now supports a defaultLanguages
config setting which will create empty array items for specific languages in new documents.
Great, thank you!
Is it possible to define a default language, so that the user does not need to click
+ EN
?i.e. when the document is rendered, get this:
instead of this:
Thanks!