I have a record in Sanity with the following fields: title (string), slug (slug), and path (string).
Is there a way to set up an initialValue for the path field that generates a custom dynamic string based on the value of the slug?
For instance, if the slug value is my-new-path
, how can I programmatically set the initialValue of the path field to /blog/events/my-new-path
?
export default {
name: "myPage",
title: "My Page",
type: "document",
fields: [
{
name: "title",
type: "string",
title: "Page Title",
validation: (Rule) => Rule.required(),
},
{
name: "slug",
type: "slug",
title: "Slug",
options: {
source: "title",
maxLength: 200, // will be ignored if slugify is set
slugify: (input) =>
input
.slice(0, 200)
.toLowerCase()
//Remove spaces
.replace(/\s+/g, "-")
//Remove special characters
.replace(/[&\/\\#,+()$~%.'`’":*?<>{}]/g, ""),
},
validation: (Rule) => Rule.required(),
},
{
name: "path",
type: "string",
title: "URL Path",
readOnly: true,
},
]
}