Trouble with generating slug field in Sanity Studio

30 replies
Last updated: Feb 7, 2023
Hi Everyone,Excited to be here. I was wondering if anyone has come across the slug field not generating. Any tips to debug/trouble shoot?
If the generate is not working, make sure you have set the
options.source
value (link ) so it knows where to derive the slug from.
Thank you for responding User!It seems like I did set the value, here’s my schema:


import {defineField, defineType} from 'sanity'


export default defineType({

title: "Event", // title of the doc, display name for the Ui

name: "event", // when performing queries and hitting API's

type: "object",


fields: [

// always an array of objects

defineField({

title: "Event Name",

name: "eventName",

type: "string",

}),

defineField({

name: "slug",

title: "Slug",

type: "slug",

options: {

source: "eventName",

maxLength: 96,

},

}),

defineField({

name: 'ticketType',

title: 'Ticket Type',

type: 'string',

options: {

list: [

{ title: 'Ticketed', value: 'tix' },

{ title: 'Guest List', value: 'gl' },

{ title: 'Discounted', value: 'dic' },

{ title: 'Soldout', value: 'so' },

],

},

}),

defineField({

title: "Date",

name: "eventDate",

type: "date",

}),

defineField({

title: 'Event URL',

name: 'eventUrl',

type: 'url'

}),

defineField({

title: "Venue Name",

name: "venueName",

type: "string",

}),

defineField({

title: "Artists Performing",

name: "artists",

type: "string",

}),

defineField({

title: "Flyer",

name: "flyer",

type: "image",

options: {

hotspot: true,

}

}),

],


}

);
Any other approach?
Hmmm AFAIK this should work as long as you first enter an event name.
Yes I was also wondering, I tried everything 😭
The only thing I can think of is that defineField somehow messes with your schema?
Let me try it without it
Not working 🥲
If that doesn't work: I'd love to help but I'm going to bed soon.
user M
seems to be eager to help people here 😇
Thanks a lot User, sorry if I have kept you up late
Hopefully she can give you some insight, I'm by no means an expert.
Really value your time, much love
Haha no worries. I love to help.
Good luck!
Thanks again
What version of the Studio is this happening in?
Hi RD,How do I find that out?
I believe it’s v3
Your Sanity Studio is version
3.2.4
. The latest version is
3.2.6
.
It may be worth updating to see if the behavior still exists. If that doesn’t fix it I’ll replicate and see if I can fix it.
That is very kind of you
Let me go ahead and do that
I have updated, and the field is still not generating
I think something odd is happening since this slug field is inside of an object. It’s likely looking for an
eventName
on the document and not finding that field since it’s nested under your
event
. I was able to get it to work by changing the source to the following:
source: (doc, { parent }) => parent.eventName,
I see what is happening, since it’s an array of events. This actually makes total sense, oh my goodness I can’t thank you enough
Happy to help!
Hello
user M
Sorry to bother you again, but I am having a hard time figuring out the right GROQ query to filter by the slugs that sit into the event category in the events document.

The [Object] below represent an event document/category


[

{

_createdAt: '2023-01-27T10:50:55Z',

_id: '26d56839-2903-4353-b039-1365f2100f81',

_rev: '0mmgc4CDWeXHLRG7XO0GKF',

_type: 'events',

_updatedAt: '2023-02-04T05:18:56Z',

city: 'sc',

events: [ [Object] ]

},

{

_createdAt: '2023-01-27T10:58:46Z',

_id: 'f3ec5bbf-e124-4503-9b58-917dee7e6569',

_rev: '0mmgc4CDWeXHLRG7X7zkHP',

_type: 'events',

_updatedAt: '2023-02-03T03:35:29Z',

city: 'sf',

events: [ [Object], [Object] ]

}

]
UPDATE: I believe this worked, however how do I compare and filter it with the local $slug
*[_type=='events']  {

events[] {

slug

}

}

I have attempted, but unfortunately it did not work

 *[_type=='event' && event.slug.current == "perro-paradise"]
Thanks again
What query are you currently using?
HI RD!!I’m extremely happy to hear from you, I’m using GROQ and have actually solved this on the frontend. However, I have pulled an all nighter attempting to push my studio to dev with no luck. I have just sent you a message!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?