Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to render fields based on conditions (computed fields) #677

Closed
vdvleon opened this issue Mar 16, 2018 · 25 comments
Closed

Possibility to render fields based on conditions (computed fields) #677

vdvleon opened this issue Mar 16, 2018 · 25 comments

Comments

@vdvleon
Copy link

vdvleon commented Mar 16, 2018

It would be great to add the possibility to render parts of a form based on values of certain fields.

E.g. imagine you have form with a few bool switches: Language: EN, Language: NL, ...
When these bools are enabled we render specific fields related to that language (title, body, etc.).

@evenwestvang
Copy link
Member

Great suggestion. There's no time to prioritize it right now, but I'll add it to our backlog.

@dmorenogogoleva
Copy link

That would be very useful

@vicmeow vicmeow added the Studio label Jan 17, 2020
@vicmeow vicmeow changed the title Possibility to render fields based on conditions Possibility to render fields based on conditions (computed fields) Jan 17, 2020
@d-darwin
Copy link

Need this feature too. In my case I have "Is a gallery" switch. Depending on its state I need to toggle Block and Images fields.

@devinhalladay
Copy link

My team really would benefit from this as well. We use Sanity for lots of large client projects and our designers (I'm one of them) worry that the UX of Sanity degrades as more fields are added and nested. Being able to "progressively disclose" fields conditionally based on, for example, a switch, radio, or dropdown, would reduce end-user cognitive load and make the CMS feel snappier and more focused.

@tayteboss
Copy link

Any development on this feature @evenwestvang ?

@menakhovsky
Copy link

Really need this feature. We want to show different sets of categories based on previous selection.

@RonaldDijks
Copy link

Also running into this particular use case. We want to show/hide a set of an object's fields depending on a boolean.

@harshilparmar
Copy link

This should look like this right!!!

I would like to contribute to this feature. I am just figuring out to understand the codebase.

Suggestion: We have two fields e.g In One for show fields (boolean) and another array of fields that we want to show on based on the former boolean value.

Untitled-2020-07-26-1717

@stordahl
Copy link

Would love this feature, any progress being made on this? Going to try to implement this in the mean time https://gist.github.com/kmelve/e34feccafe8e9ee3c7e09d60ee3fd4d2

@jamesryan-dev
Copy link

+1 for this feature

@tirmey
Copy link

tirmey commented Jan 23, 2021

+1 for this feature!

@mehrad-meraji
Copy link

+1

@PetterRuud
Copy link
Contributor

Any progress on this issue?

@ElizabethCapararo
Copy link

+1 for this feature. Hope to see it soon!

@jamesryan-dev
Copy link

There is this alternative headless CMS which provides what we're looking for FYI
https://payloadcms.com/

@mehrad-meraji
Copy link

@jamesryan-dev this looks great thank you!

@cdedreuille
Copy link

+1. Would be absolutely awesome to have a simple way to do that.

@RawmanGrey
Copy link

+1, seems like a vital feature to have

@jonathanredford
Copy link

+1 would love to see this implemented

@hdoro
Copy link
Contributor

hdoro commented Apr 22, 2021

For those who need this functionality ASAP, you can use this small plugin I made: https://github.com/hdoro/sanity-plugin-conditional-field

Keep in mind this plugin is meant to be replaced with the official implementation once the Sanity team can prioritize it. It's a band-aid solution.

By the way, would love to get @bjoerge 's input on the solidity of this approach as compared to what the official one is aiming at:

https://github.com/hdoro/sanity-plugin-conditional-field/blob/881d8ffdd776bcc6aaa071cd416d968027a53a40/src/ConditionalField.tsx#L32-L54

@tirmey
Copy link

tirmey commented Apr 23, 2021 via email

@winsvold
Copy link
Contributor

For those who need this functionality ASAP, you can use this small plugin I made: https://github.com/hdoro/sanity-plugin-conditional-field

Keep in mind this plugin is meant to be replaced with the official implementation once the Sanity team can prioritize it. It's a band-aid solution.

By the way, would love to get @bjoerge 's input on the solidity of this approach as compared to what the official one is aiming at:

https://github.com/hdoro/sanity-plugin-conditional-field/blob/881d8ffdd776bcc6aaa071cd416d968027a53a40/src/ConditionalField.tsx#L32-L54

Thanks a lot for sharing this Henrique, works perfectly, nice and simple 👌 🎉

@evenwestvang
Copy link
Member

Hi everyone, thank you for your patience on this. There is now a canary out on sanity upgrade --tag=conditional-fields --save-exact. Guidance on usage may be found in the #beta channel on https://slack.sanity.io, but briefly:

{
      name: 'article',
      type: 'document',
      title: 'Article',
      fields: [
        {
          name: 'title',
          type: 'string'
        },
        {
          name: 'subtitle',
          type: 'string',
          hidden: ({parent, document, value}) => {
            return !document.title
          }
        }
      ]
   }

@ricokahler
Copy link
Contributor

This is now available in v2.17.0 🎉

@felixhaeberle
Copy link

Thank you really much for making this available. This was definitely needed and makes content editing so much more powerful and versatile. 🤘🏆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests