sanity-plugin-media icon indicating copy to clipboard operation
sanity-plugin-media copied to clipboard

How to configure custom fields?

Open roblom opened this issue 2 years ago • 5 comments

Hi, in your FAQ it reads "If you want to set values you can query in all instances of that asset (alternate text being a good example), consider setting those in the plugin". I want to add "copyright" as a field that I can query in all instances of the image, how can I add this field?

If that faq-text doesn't mean it's possible have such values though the plugin, can you please give some tips on what else to "consider" (as the faq-text says)? :-)

Thanks!

roblom avatar Jan 21 '23 21:01 roblom

Having the same issue. I want to add new fields to assets, but can't find any examples nor explanation of how to do it. Is it even possible?

Atle91 avatar Jan 31 '23 08:01 Atle91

Interested in this feature as well!

mashaal avatar Apr 06 '23 01:04 mashaal

@robinpyon Any updates here? We all want to know if there is a way to add custom fields to assets 🙂

sebastian-kopiczko avatar Nov 07 '23 07:11 sebastian-kopiczko

This feels very related to this issue i just opened: https://github.com/sanity-io/sanity/issues/5367 Maybe this is the more correct repo to raise the issue in?

piofinn avatar Dec 14 '23 10:12 piofinn

A workaround for this: on your image object definition, add a dummy field of the type you want. I.e.

{
  type: 'image',
  fields: [
    {
      name: 'globalCaptionField',
      title: 'Caption',
      type: 'string',
      components: {
        input: MyCustomComponent
      }
    }
  ]
}

Have MyCustomComponent handle a change to the input by patching the asset's fields

good-idea avatar Jun 18 '24 17:06 good-idea