🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Issue with "Create new document" option not showing for a specific field in a menu.

3 replies
Last updated: Mar 25, 2021
Hey guys, I have created a field (Page/Pages) for my menu. But for some reason it is not showing “Create a new page” option. This works for my different field types. Any idea? Create new document for this type is missing. No errors but It is showing up in the menu.
Page field:


import { UniqueSlug } from "../../lib/helpers";


export default {

name: "page",

title: "Pages",

type: "document",

fields: [

{

title: "Naslov",

name: "title",

type: "string",

validation: (Rule) => Rule.required().error("Naslov je obavezan"),

},

{

name: "slug",

title: "Slug",

type: "slug",

validation: (Rule) => Rule.error("Slug/Link je već u upotrebi"),

options: {

source: "title",

maxLength: 100,

slugify: (input) =>

input.toLowerCase().replace(/\s+/g, "-").slice(0, 100),

isUnique: UniqueSlug,

},

},

{

name: "autor",

title: "Autor",

type: "reference",

to: { type: "autor" },

},

{

name: "mainImage",

title: "Glavna slika",

type: "image",

fields: [

{

title: "Alternativni tekst",

name: "alt",

type: "string",

validation: (Rule) =>

Rule.required().error("Alternativni tekst je obavezan"),

},

],

options: {

hotspot: true,

accept: "image/*",

},

validation: (Rule) =>

Rule.custom(async (image) => {

// short circuit if no image

if (!image) return true;

`const result = await client.fetch(
*[_id == $id][0].size
, {`
id: image.asset._ref,

});


return result <= 1_000_000 || "1MB je limit slike.";

}),

},

{

name: "publishedAt",

title: "Objavljeno u",

type: "datetime",

},

{

name: "body",

title: "Sadržaj",

type: "blockContent",

},

],

preview: {

select: {

title: "title",

author: "autor.name",

publishedAt: "publishedAt",

media: "mainImage",

},


prepare(selection) {

const { author, title = "Nema naslova", publishedAt } = selection;


return Object.assign({}, selection, {

title,

subtitle:

publishedAt &&
```

Datum objave ${publishedAt}
,

      
});`
},

},

};


My desk structure:


// deskStructure.js

import S from "@sanity/desk-tool/structure-builder";


import {

IoFastFoodOutline,

IoPersonOutline,

IoTicketOutline,

IoSettingsOutline,

IoDocumentTextOutline,

} from "react-icons/io5";


export default () =>

S.list()

.title("Sadržaj")

.items([

S.listItem()

.title("Pages")

.icon(IoDocumentTextOutline)

.schemaType("page")

.child(S.documentTypeList("page").title("Pages")),


S.listItem()

.title("Recepti")

.icon(IoFastFoodOutline)

.schemaType("recept")

.child(S.documentTypeList("recept").title("Recepti")),


S.listItem()

.title("Kategorije")

.icon(IoTicketOutline)

.schemaType("category")

.child(S.documentTypeList("category").title("Kategorije")),


S.listItem()

.title("Autori")

.icon(IoPersonOutline)

.schemaType("autor")

.child(S.documentTypeList("autor").title("Autori")),


S.divider(),

S.listItem()

.title("Postavke")

.icon(IoSettingsOutline)

.child(

S.editor().schemaType("siteSettings").documentId("siteSettings")

),


`//
S.documentTypeListItems()
returns an array of all the document types`

// defined in schema.js. We filter out those that we have

// defined the structure above.

...S.documentTypeListItems().filter(

(listItem) =>

!["autor", "recept", "category", "siteSettings", "page"].includes(

listItem.getId()

)

),

]);
Mar 24, 2021, 4:54 PM
Hey Nino, to be clear, all other types in this structure have a new document button except the
page
type, correct?
Mar 24, 2021, 5:24 PM
user M
Yes, that is correct! It is basically a copy of “recipes” but with a different name &amp; title and fields.
I am not sure if it is a bug. But it seems if you customize the “Create new document” to add icons. The “field/pages” will not show “Create new document” menu in the right corner. Very weird.. Basically it makes it required to also add that specific field to the “Create new document” otherwise the “Create new document” will not show up.
Mar 24, 2021, 7:37 PM
I’m glad you got it working!
Mar 25, 2021, 1:23 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?