Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🤠 July 18th

Improving schema setup for adding bold and italics to a title/string field in Slack thread.

3 replies
Last updated: Jul 21, 2023
Hey all, looking for a schema setup where I can add bold, & italics to a title/string field. Current setup is to use an array/block and then limit it to 1 line via validation. This works but looks like overkill. Anyway to improve this setup, loose aim at getting the WYSIWYG height to that of a string field and maybe disabling the ability to hit return?
Jul 19, 2023, 12:59 PM
{
      name: 'headingBlock',
      title: 'Hero Title block',
      // fieldset: 'hero',
      of: [
        {
          type: 'block',
          styles: [{title: 'Normal', value: 'normal'}],
          lists: [],
          marks: {
            decorators: [
              {title: 'Strong', value: 'strong'},
              {title: 'Emphasis', value: 'em'},
            ],
          },
        },
      ],
      type: 'array',
      validation: (Rule) =>
        Rule.custom((value, {document}) => {
          if (value && value?.length > 1) {
            return 'This is a title and so can only be one line.';
          }
          return true;
        }),
    },
Jul 19, 2023, 12:59 PM
I don’t think there’s a clean way to do this, unfortunately.
Jul 19, 2023, 4:47 PM
No worries, this setup works fine, it was just the details I was getting caught up on. Thanks!
Jul 21, 2023, 9:00 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?