Is it possible to add to sanity field with default value? How can I extend it? I want to create some fields with default variables. For example I have this code:
export default {
name: 'name',
title: 'name',
type: 'document',
fields: [
{
name: 'title',
title: 'title',
type: 'string',
validation: Rule => Rule.required(),
},
{
name: 'key',
title: 'key',
type: 'slug',
options: {
source: 'title',
maxLength: 96
}
},
{
name: 'geo',
title: 'geo',
type: 'geopoint',
//default: {"lat": 1,"lng": 2}
},
{
name: 'tel',
title: 'tel',
type: 'string',
//default: '122334554565'
},
],
preview: {
select: {
title: 'title'
}
}
}
Is it possible to add to sanity field with default value? How can I extend it? I want to create some fields with default variables. For example I have this code:
export default {
name: 'name',
title: 'name',
type: 'document',
fields: [
{
name: 'title',
title: 'title',
type: 'string',
validation: Rule => Rule.required(),
},
{
name: 'key',
title: 'key',
type: 'slug',
options: {
source: 'title',
maxLength: 96
}
},
{
name: 'geo',
title: 'geo',
type: 'geopoint',
//default: {"lat": 1,"lng": 2}
},
{
name: 'tel',
title: 'tel',
type: 'string',
//default: '122334554565'
},
],
preview: {
select: {
title: 'title'
}
}
}
Share
Improve this question
edited Feb 19, 2019 at 20:51
kizoso
asked Feb 19, 2019 at 16:00
kizosokizoso
1,2462 gold badges18 silver badges31 bronze badges
1 Answer
Reset to default 7You can now use Initial Value Templates to do this:
export default {
name: 'name',
title: 'name',
type: 'document',
initialValue: {
tel: 122334554565,
geo: {
_type: 'geopoint',
lat: 1,
lng: 2
}
},
fields: [
{
name: 'title',
title: 'title',
type: 'string',
validation: Rule => Rule.required(),
},
{
name: 'key',
title: 'key',
type: 'slug',
options: {
source: 'title',
maxLength: 96
}
},
{
name: 'geo',
title: 'geo',
type: 'geopoint',
},
{
name: 'tel',
title: 'tel',
type: 'string',
},
],
preview: {
select: {
title: 'title'
}
}
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744132316a4559896.html
评论列表(0条)