👀 See Sanity in action: Watch product demo now →

Can you Conditionally Change the Options of an Image Type?

5 replies
Last updated: May 24, 2022
can you conditional change the options of an image type ?
May 24, 2022, 4:55 PM
What do you mean?
May 24, 2022, 5:06 PM
umm if i defined a field under the type image. there is an option to highlight the field or not. can this be conditionally changed (optionally change isHighlighted between true and false)? below is a field example
export default {
  name: 'illustration',
  title: 'Illustration',
  type: 'image',
  fields: [
    {
      name: 'alt',
      type: 'string',
      title: 'Alt',
      options: {
        isHighlighted: true, // <-- make this field easily accessible
      },
    },

  ],

};
May 24, 2022, 5:12 PM
Because of the way the schema is compiled, I believe you'd need to use the hidden callback. Similar to this previous thread.
May 24, 2022, 6:10 PM
I thought about that but my document has multiple fields that is typed ‘illustration’ and I cannot distinguish them from each other based on document / parent… am i approaching this wrong?
May 24, 2022, 6:16 PM
thanks
user F
+
user M
for helping with this. We have decided to keep the field highlighted if there is no good work around. The only alternative that I can think of is to define more schema to accommodate the variance… which is probably not worth it if it’s just highlighting a field or not…
May 24, 2022, 6:34 PM

Sanity.io – build remarkable experiences at scale

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

Categorized in