9

is it somehow possible to conditionally show or hide fields in the entry editor based on the value of another previously entered field?

An example of this use would be:

  • A section has Lightswitch field "hasVideo"
  • User is populating a new entry for this section and sets "hasVideo" to the value of choice.
  • If user sets hasVideo to true, show a text field "productVideo" so that the user can set a link to a youtube video, but hide assets field "productImage".
  • If user sets hasVideo to false, how Assets field "productImage" so that the user can upload an image, but hide "productVideo" field.

This would really help from a usability perspective since the client will only be shown the fields that need to be filled based on what was filled earlier on - creating a sort of entry creation "wizard".

Naturally there might be an alternative route to achieve the same level of usability that I'm missing.

Thanks in advance!

9

The feature request for this has been very popular since day one, so hopefully it's something P&T adds to the core some day.

For the interim I just published a small plugin called Reasons, which will add simple field/value based conditionals to entry type field layouts - pretty much exactly like the OP describes it.

Download from GitHub: https://github.com/mmikkel/Reasons-Craft

Edit P&T retired the UserVoice page; here is the new home for the feature request

| improve this answer | |
  • Since Reason has been abadoned, please vote this idea here – ricricucit Mar 23 '18 at 16:26
  • 1
    @ricricucit Field layout conditionals is coming as a Native feature, but no word on when (definitely not in 3.0, but hopefully in a minor 3.x release :) – Mats Mikkel Rummelhoff Mar 24 '18 at 16:42
  • 1
    Oh - and Reasons has not been abandoned, per se; I just patched it last month. It won’t get ported to Craft 3, though (unless somebody else does it, of course) – Mats Mikkel Rummelhoff Mar 24 '18 at 16:43
5

No, Craft doesn't offer conditionals in field layouts. Coming from Wordpress/ACF, I'd personally like to see something like that implemented in the future, but for now I can think of two possible workarounds for your specific scenario:

  1. Set up two different Entry Types for your "products" section, e.g. "Video" and "Image". Design identical field layouts for the two, apart from including the field "productVideo" for the former, and "productImage" for the latter.

  2. Use only one entry type, but replace the "productVideo" and "productImage" fields with a Matrix field called "productMedia" or the like. Set up two block types for the Matrix field; one for "productVideo", and one for "productImage". Limit the Matrix field to maximum one block.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.