How to resolve Slack thread issue in Sanity community?

21 replies
Last updated: Mar 19, 2023
AI Update

I can see you're trying to share a Slack thread, but unfortunately I'm unable to access Slack links directly. Slack conversations are private and not publicly accessible, so I can't see what specific issue you're encountering.

To help you effectively, please share the relevant details from that Slack thread directly here:

  • What error message or issue are you experiencing?
  • What are you trying to accomplish?
  • Any relevant code snippets or configuration
  • Which Sanity feature or tool you're working with (Studio, GROQ queries, schema definitions, content modeling, etc.)

Once you provide those details, I'll be able to search the documentation and give you a proper solution!

In the meantime, if you're looking for community support, here are some great resources:

Just paste the details of your issue here and I'll be happy to help troubleshoot!

Show original thread
21 replies
user U
Already replied above
user Z
i already did that and got typescript error Argument of type '{ name: "audio"; title: string; type: "file"; accept: string; }' is not assignable to parameter of type '{ type: "file"; name: "audio"; } & Omit<FileDefinition, "preview"> & { preview?: PreviewConfig<Record<string, string>, Record<never, any>> | undefined; } & FieldDefinitionBase'. Object literal may only specify known properties, and 'accept' does not exist in type '{ type: "file"; name: "audio"; } & Omit<FileDefinition, "preview"> & { preview?: PreviewConfig<Record<string, string>, Record<never, any>> | undefined; } & FieldDefinitionBase'.ts(2345)
user U
Can you paste me your schema, please?
Ok. Wait.
this is like my whole schema 
import {defineType, defineField} from 'sanity'

export default defineType({
  name: 'sets',
  title: 'Sets',
  type: 'document',
  fields: [
    defineField({
      name: 'setNumber',
      title: 'Set Number',
      description: 'यहाँ Set Number लेख्नुहोस् र यो नम्बर दोहोर हुनु हुँदैन।',
      type: 'number',
      validation: (Rule) => [Rule.required(), Rule.min(1)],
      placeholder: 'eg: 1',
    }),
    defineField({
      name: 'slug',
      title: 'Slug',
      description: 'Set Number लेखेपछि Generate बटनमा क्लिक गर्नुहोस्',
      type: 'slug',
      options: {
        source: 'setNumber',
        slugify: (input) => 'set-' + input,
      },
      validation: (Rule) => Rule.required(),
    }),
    defineField({
      name: 'questions',
      title: 'Questions',
      type: 'array',
      of: [
        {
          type: 'object',
          name: 'set',
          title: 'Set',
          fields: [
            defineField({
              name: 'questionNumber',
              title: 'Question Number',
              description: 'यहाँ Question Number दिनुहोस् र नम्बर दोहोर हुनु नदिनुहोस्।',
              type: 'number',
              validation: (Rule) => [
                Rule.required().error(
                  ' यहाँ Question Number दिनुहोस् र नम्बर दोहोर हुनु नदिनुहोस्।'
                ),
                Rule.min(1).error(' 1 भन्दा बढी नम्बर हुनुपर्छ'),
              ],
              placeholder: 'eg: 1',
            }),
            defineField({
              name: 'question',
              title: 'Question ',
              description: 'Question यहाँ लेख्नुहोस् ',
              type: 'string',
              validation: (Rule) => Rule.required().error('Question लेख्नुहोस् यहाँ'),
            }),
            defineField({
              name: 'audio',
              title: 'Audio ',
              type: 'file',
            }),
            defineField({
              name: 'options',
              title: 'Options ',
              type: 'array',
              of: [
                {
                  type: 'object',
                  name: 'answer',
                  title: 'Answer',
                  fields: [
                    defineField({
                      name: 'answerText',
                      title: 'Answer',
                      type: 'string',
                      validation: (Rule) => Rule.required(),
                    }),
                    defineField({
                      name: 'isCorrect',
                      title: 'सही भए यसलाई छुनु नत्र भए यसलाई नछुनु',
                      type: 'boolean',
                      initialValue: false,
                    }),
                  ],
                },
              ],
              validation: (Rule) => [
                Rule.custom((answers) => {
                  if (!Array.isArray(answers)) {
                    return 'जवाफहरू लेख्नको लागि "Add Item" मा क्लिक गर्नुहोस् र जवाफ लेख्नुहोस्।'
                  }
                  if (answers.length < 4) {
                    return `कम्तिमा ४ जवाफहरु हुनुपर्छ, तर ${answers.length} जवाफ मात्र प्रदान गरिएका छन्`
                  }
                  if (answers.length > 4) {
                    return `अधिकतम ४ जवाफहरु हुन सक्छन्, तर ${
                      answers.length
                    } जवाफहरु प्रदान गरिएका छन्! ${answers.length - 4} जवाफ Delete गर्नुहोस्`
                  }
                  const numCorrect = answers.filter((answer) => answer.isCorrect).length
                  if (numCorrect === 0) {
                    return 'कम्तिमा एउटा जवाफ सही हुनुपर्छ'
                  }
                  if (numCorrect > 1) {
                    return `केवल एउटा जवाफ सही हुन सक्छ! तर तपाईंले ${numCorrect} जवाफमा Tick लाउनु भएको छ`
                  }
                  return true
                }),
              ],
            }),
          ],
          preview: {
            select: {
              number: 'questionNumber',
              question: 'question',
            },
            prepare({number, question}) {
              return {
                title: `Question (${number}) - ${question ? question : 'Question लेखन भुलिनुभयो'} `,
              }
            },
          },
        },
      ],
      validation: (Rule) =>
        Rule.custom((questions) => {
          if (!Array.isArray(questions)) {
            return '40 ओटा प्रश्नहरु लेख्नुहोस्।'
          }
          if (questions.length !== 40) {
            return 'Questions 40 ओटा भन्दा बढी या कम हुनु हुदैन'
          }
          return true
        }),
    }),
  ],

  preview: {
    select: {
      title: 'setNumber',
    },
    prepare({title}) {
      return {
        title: `Set-${title} `,
        subtitle: `By Govinda Dhakal`,
        imageUrl: '../static/govinda.jpg',
      }
    },
  },
})
this is my whole schema and audio is simply this
defineField({
name: 'audio',
title: 'Audio ',
type: 'file',
accept: 'audio/*',
}),
Robin, your issue is you're not using "options.accept". This is what you're looking for:
            defineField({
              name: 'audio',
              title: 'Audio ',
              type: 'file',
              options: { accept: 'audio/*' },
            }),
user Z
thanks it worked and also can i do conditional rendering here
defineField({
name: 'question',
title: 'Question ',
description: 'Question यहाँ लेख्नुहोस् ',
type: 'string',
validation: (Rule) =&gt; Rule.required().error('Question लेख्नुहोस् यहाँ'),
}),
defineField({
name: 'audio',
title: 'Audio ',
type: 'file',
options: {accept: 'audio/*'},
}), like if there is a text in question, hidden true to audio field and if there is a audio file selected, question field hidden
Yes. You can use Sanity's hidden property as a function, e.g. hidden: ({ parent }) =&gt; !!parent?.question in the audio file will hide it if question has any text in it
The related documentation is a great place to start: https://www.sanity.io/docs/conditional-fields
user Z
thanks, that worked out too, and now here defineField({ name: 'setNumber',
title: 'Set Number',
description: 'यहाँ Set Number लेख्नुहोस् र यो नम्बर दोहोर हुनु हुँदैन।',
type: 'number',
validation: (Rule) =&gt; [Rule.required(), Rule.min(1)],
placeholder: 'eg: 1',
}),
defineField({
name: 'slug',
title: 'Slug',
description: 'Set Number लेखेपछि Generate बटनमा क्लिक गर्नुहोस्',
type: 'slug',
options: {
source: 'setNumber',
slugify: (input) =&gt; 'set-' + input,
},
validation: (Rule) =&gt; Rule.required(),
}), can i also generate slug without even clicking on generate button, i want it hidden and it has to get auto generated when i type setNumber,
user U
While you can do that, I believe you'd need to go a bit too far to make that one happen, so best leave the slug field visible
you know how clients are, they are stupid. they want it hidden and gets auto generated
user U
I would tell them to settle for this one. In order to make this happen you'd need to write a custom component for your type, which would take you some time, but it's still possible
user Z
and now here defineField({ name: 'questions',
title: 'Questions',
type: 'array',
of: [
{
type: 'object',
name: 'set',
title: 'Set',
fields: [
defineField({
name: 'questionNumber',
title: 'Question Number',
description: 'यहाँ Question Number दिनुहोस् र नम्बर दोहोर हुनु नदिनुहोस्।',
type: 'number',
validation: (Rule) =&gt; [
Rule.required().error(
' यहाँ Question Number दिनुहोस् र नम्बर दोहोर हुनु नदिनुहोस्।'
),
Rule.min(1).error(' 1 भन्दा बढी नम्बर हुनुपर्छ'),
],
placeholder: 'eg: 1',
}), can i make the question number auto incremented
The documentation will mostly answer all of those questions as you walk through it. You're looking for this: https://www.sanity.io/docs/initial-value-templates#f853d3151a21
Now, I am not particularly aware if you can read document information from initialValue, but there's the fetch route
If your question number is just its index + 1, you don't need a question number at all in your schema, right?
If a field's value is always derived from another field, the field shouldn't exist in the first place, technically speaking
and now this is the final question i swear🥳🥳, can i make the string or even number field unique?

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?