Issue with custom input field schema in Sanity, resolved by importing custom type in schema.js
3 replies
Last updated: Dec 14, 2020
N
hey, I’m having problems when building custom input field schema. I’m getting
even though I have this custom
I’m a bit unclear, what exactly doesn’t work? Can Sanity not see
To clarify, I’m trying to use default
any thoughts? ideas?
Unknown type: commercejsProducts. Valid types are: post, author, category, blockContent, array, block, boolean, datetime, date, document, email, file, geopoint, image, number, object, reference, slug, string, telephone, text and url
commercejsProductsfield defined in
schemas/commerceProducts.js
import CommercejsProducts from "../components/CommercejsProducts"; export default { name: "commercejsProducts", title: "Commercejs Products", type: "array", of: [ { type: "object", fields: [ { name: "price", type: "object", fields: [ { name: "raw", type: "number", }, ], }, { name: "quantity", type: "number", }, { name: "media", type: "object", fields: [ { name: "type", type: "string", }, ], }, { name: "categories", type: "array", of: [ { type: "object", fields: [ { name: "id", type: "string", }, ], }, ], }, ], }, ], inputComponent: CommercejsProducts, };
commercejsProductsat all or is it the fact that I have more nested objects in it?
To clarify, I’m trying to use default
post.jsschema to enter my products there
export default { ...default post.js... fields: [ { title: "Related products", name: "commercejsProducts", type: "commercejsProducts", }, ], ...default post.js... };
Dec 13, 2020, 12:12 PM
N
I think I’m having similar issue https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1607793530159600
Dec 13, 2020, 12:16 PM
N
ahhhhh, never mind, found what went wrong 🤦 For the recrod, when you define custom
typeyou need to import it in
/schemas/schema.js
export default createSchema({ types: schemaTypes.concat([ [other default types are imported here] commercejsProducts, // THAT ]), });
Dec 13, 2020, 12:21 PM
B
Great to hear that you found the solution 😄
Dec 14, 2020, 7:44 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.