10

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!

2 Answers 2

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

3
  • Since Reason has been abadoned, please vote this idea here
    – ricricucit
    Commented Mar 23, 2018 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 :) Commented Mar 24, 2018 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) Commented Mar 24, 2018 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.

8
  • 1
    Sounds like a great feature request!
    – Brad Bell
    Commented Mar 8, 2015 at 23:38
  • 1
    Don't mind if I do, @BradBell! Just posted a (fairly lenghty) request. Commented Mar 9, 2015 at 0:14
  • Thanks... we've only soft launched that site so you're the first!
    – Brad Bell
    Commented Mar 9, 2015 at 0:16
  • Oh, I didn't realize – very cool! Commented Mar 9, 2015 at 0:16
  • Yes. The List is back!
    – carlcs
    Commented Mar 9, 2015 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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