Dynamic Content Fields (Conditional Fields)

Is it possible to add dynamic fields to a content type? For example, I add a boolean type to a content type. If the user chooses the true/yes option, then another content field appears for the user to add additional data? Is this currently possible in Prismic? If not is this a feature that could be in planning?

10 Likes

Hi Charles,

Unfortunately conditional dynamic fields like this aren’t available in Prismic at the moment. I’ve added a tick to our feature request tracker to let the team know of your interest in this.

A good solution for your use case would be to use our slices feature.
https://prismic.io/feature/dynamic-layout-content-components

You could create whatever building blocks you want to give you content creators and then the can choose from that list what they need to build the page layouts they desire.

Here’s some information to show how to template slices in your project:
https://prismic.io/docs/javascript/templating/slices
These are the JS docs but the same article is in the other technologies.

Hey @charles,

We are working on a feature that can work for some of the uses cases of conditional fields.
I will be really interested in the use case that you’re having. Do you have some details that you can share? Maybe mockups that will explain the context of your need for this feature ?

It might also be interesting that we present you some of our early work, if it fits your use case.

Thanks a lot.

Heads up, the slices picker is going to get CLUTTERED and hard to choose from soon.
My little shop alone can think of 40 different widgets that we want included on a “web page” content type, and it’s going to get hard to navigate.
Also, might be cool to allow users to upload their own svgs for slice icons.

1 Like

@renaud

I also have the need for conditional fields. The suggestion above to use slices does not help us much, because we use the slices on a higher level of abstraction.

One of my specific use cases is a two column layout that can be filled with text and images.

There are some general fields such as a background for the entire columned layout and then there are specific fields for each column. Depending on what type of column it is, e.g. image or text, the user should fill out different fields.

Since the conditional fields are not available yet I solve this by adding more information to the fields, to indicate which fields are relevant for each column type. However, this soon becomes hard to keep track of and I become reluctant to add more fields, even though it would be useful. The user experience would be much better if we could have a conditional field that added some fields. You could draw inspiration from how fragments work in Graphql.

4 Likes

Dynamic content fields would also be super useful for us at Monito, happy to test the feature you aer working on @renaud or to share some of our user-cases.

4 Likes

I want my user to choose between uploading an image or just specify a string url. So I wish they first select the type of input then conditionaly either display an image picker, or an input field. Is there any progress on the conditional field rendering?

1 Like

Hi Tommy,

This is a great use case. The progress on this is that it's something that we plan to release with Slice Machine in the coming months. So it's not available right away, but we're are working hard to get it out there.

Thanks.

2 Likes

This is being tracked as an open feature request.

If you have another use-case for this feature, you can 'Flag' this topic to reopen. Please use the :heart: button to show your support for the feature and check out our Feature Request Guidelines.

Hi @tommy.zrce, @charles, @tech1, @juj, @ecalvo,

This feature is now available with the Beta version of Slice Machine as 'Variations' and should be on the stable version very soon.

Thanks.

Threads close after a period of inactivity. Flag this thread to re-open it and continue the conversation.

Variations is very helpful, but not the right substitution for conditional fields. Whenever you create a variation it just duplicates the fields from the original instead of referencing the fields that you wouldn't want changed.

For example, I have button slice. I have a field for label (key text) and color options (select field). These fields will be consistent in both the default slice and the variation slice.

Then there's an 2 extra fields I want in for the variation slice only.

Later on, the color options have changed. Therefore, I now have to manage these color changes in both the default slice and variation slice. Of course, this is a simple example, but the more slices and slice variations you have, it's going to become more complex to maintain.

This is not a DRY solution.

3 Likes

Hi Scott,

Thanks for the feedback, I can see what you mean about managing the same field across multiple variations. I believe we have previously discussed this with the team, so I'll get their feedback on why we didn't go down that route straight away.

Also, just to be clear you're only talking about 'source/replica' fields for the model and not for the actual content, right? Because that's another conversation.

Thanks.

So I talked with the team, and it's not something they are working on, but we have logged this as a feature request.

Should they decide to implement this feature, it will happen the Slice Machine UI. This means that because each variation is independent of the other it will be up to the UI to apply any changes across the different variations.

If/when there are any updates on this the team will update you here.

Thanks.

Hey Phil, Thanks for your responses and insight.

Since ACF has been a staple in my life for over a decade, it's going to be hard not to compare it to other services and products like Prismic, Strapi, Directus, Sanity, etc.

Like most developers, I started getting fed up when WP introduced Gutenberg, not because the main content editor was moving away from Tinymce, but because their implementation was a missed opportunity. Besides, their built-in custom fields were always treated as 2nd-class citizens. On the plus side, Elliot Condon created ACF.

Basically, I see Prismic Slice Machine's Slices as Gutenberg's Blocks done right – the missed opportunity I mentioned earlier.

Speaking of ACF, there are fields or features I miss that aren't available in Prismic like conditional logic as mentioned initially. The other is the Clone field, so you can write even more DRY logic. For example, a button component that can be referenced within other larger components, like a hero block or slice.

It would be great to be able to nest components within components in the same way InnerBlocks can be used in WP with ACF. (Sorry, there's no direct link to <InnerBlocks />. It's further down the page.) For example, creating a layout component detached from other components, but relatable only to its children would be helpful.

Hi again Scott,

So for your follow up feature requests:

This one is really interesting, if Slices were Macro components, then this would be Micro components. I've passed this idea to the team.

For you the following feature:

This has already been discussed here:

I really like all your suggestions and think they make a lot of sense to boost productivity.

Thanks.

Hello,

I would also like to see conditional fields implemented similar to how ACF in WordPress allows you to make a selection and show or hide fields based on that selection. A good use case example is a media gallery.

  • Media (group field)
    • Type (select field - options for image, video)
    • Image (image field - conditionally show if Type = image)
    • Video (embed field - conditional show if Type = video)

I currently have a similar setup, but the client lands up entering both the image and video for a media item instead of one or the other.

Hey @thehatcherylabs ,

Have you heard about variations of Slices when using Slice Machine?

Thanks.