Conditionals in field layouts #8099
-
Coming from Wordpress and ACF, I miss being able to set up simple conditionals for fields. An example scenario: A field layout for the section "Albums" includes a true/false called "Compilation". If unchecked, the layout displays a text input field called "Artist name". If checked, the "Artist" field is hidden and replaced by a Table field called "Artists", where the author is able to enter any number of artists featured on the album. In ACF, all fieldtypes has a "Conditional logic" checkbox. If checked, the field creator is able to build their conditions for showing or hiding the field, based on any selectable (as in checkbox, radio buttons, dropdowns, true/false etc) "sibling" fields in the same Field Group (or Layout, as it were). You can also apply conditionals to fields inside Repeaters (ACF's version of the Table field) and Flexible Content (Matrix) fields, which works the same way – the conditonal builder UI relies on selectable "sibling" fields in the current context. In the example scenario, the condition for showing the "Artist" field would be [IF "Compilation" IS NOT EQUAL TO "checked"], and for the "Artists" field it would be the opposite. Conditionals are not super important in Craft, as we have Entry Types, but I can definitely see use cases where one would be more elegant than the other, and I'm often encountering situations where creating a whole separate entry type just to be able to offer a small amount of flexiblity in the layout just seems a bit overkill. If Craft had conditionals, I'd use Entry Types only when the field layout would be more different than similar across various content types in the same section. To close, one huge difference between Craft and ACF is obviously that fields in Craft are shared between layouts, whereas fields in ACF are tightly coupled to their group. This means that any conditional logic in Craft would probably have to be applied in the Layout Designer (possibly by adding a "Conditional logic" button to the fields' cogwheel/settings button, which could then load up a conditionals builder in a modal or whatever) and not when creating any individual field. For Matrix fields, however, it would make sense to be able to add conditionals across block types and their fields in a more similar manner to the ACF way. |
Beta Was this translation helpful? Give feedback.
Replies: 60 comments 5 replies
-
Just wanted to let voters know that I've updated the Reasons plugin today, with support for all native element types (Entries, Users, Assets, Categories, Tags and Global Sets), as well as support for element editor modals: https://github.com/mmikkel/Reasons-Craft/ |
Beta Was this translation helpful? Give feedback.
-
We would love to add conditional layouts in our Sprout Forms plugin, but we also have the need for conditional layouts in several other Field Layouts. We'd prefer not to re-invent the wheel and love the consistency throughout Craft's interface and would like to stay true to it as much as possible. I'd love to see Craft implement this in core, at least for simple conditionals. If there is a need for more advanced conditionals, maybe that can be handled by allowing plugin developers to add new conditional options for users to choose from. |
Beta Was this translation helpful? Give feedback.
-
FYI: I wrote a plugin which implements conditionals in field layouts: https://github.com/mmikkel/Reasons-Craft Considering the popularity of this FR, it's probably not impossible that field layout conditionals will end up in core some day – until then though, I hope Reasons will be a decent patch. Please not that the plugin is in a really early state, and there will be more to come. I'm also curious about what people think about the template side of things – should field layout conditionals affect templating in some way? Currently, Reasons is strictly about increasing usability in entry forms (same as ACF) and the conditionals are not available to templates in any way. One idea that has been thrown around is to add a "visible" true/false property to the fields. I'm on the fence about whether this is needed or not, though. |
Beta Was this translation helpful? Give feedback.
-
@daryl The way this works in ACF, the field layout conditionals have no effect on the template side. It's strictly a CP UX effort, where single fields are hidden/displayed on context in order to elevate usability for the editor. To follow the above example; this would mean that even if the single "Artist" field is hidden in the CP (because the editor has checked the "Compilation" lightswitch), it may contain data and the template will need its own conditionals, yes. |
Beta Was this translation helpful? Give feedback.
-
How would this work in the template? You'd have two sets of conditionals to account for... |
Beta Was this translation helpful? Give feedback.
-
@Arik Jones: Yeah, like I mentioned in the description above, the conditionals would have to be defined in the FieldLayout somehow. As the fields are shared, there's really nowhere else that makes sense. I actually put together a super quick mockup to illustrate the basic idea (in terms of UI) as outlined in the description. There are problems and the "conditional builder" is a blatant ACF rip-off, but to illustrate: http://cly.mmikkel.no/image/16381k163G2n/1.jpg As for field dependencies, I'm not sure I follow 100% but to me that sounds like a good addition to the proposed conditionals, not really a better/different approach entirely? |
Beta Was this translation helpful? Give feedback.
-
Also, you could optionally look for specific values. |
Beta Was this translation helpful? Give feedback.
-
A better approach would be field dependencies. Field X depends on non-null values in fields A,C and U. I would think we would probably do this in the Field Layout screens. That way you're not pigeon held by the default field configs. |
Beta Was this translation helpful? Give feedback.
-
Bonus points for conditionals affecting the required-ness of subsequent fields! e.g. if I flip lightswitch A, fields B and C show up and become required. |
Beta Was this translation helpful? Give feedback.
-
Also prob worth checking out the latest ACF release... they redid conditionals and it offers a lot of power and flexibility: https://www.advancedcustomfields.com/blog/acf-pro-5-7-0-new-architecture-new-features/ |
Beta Was this translation helpful? Give feedback.
-
Really hoping this happens. |
Beta Was this translation helpful? Give feedback.
-
Recently forced to do a WP site at work, and while Craft is better in every possible way, the ACF conditionals are a game-changer. Migrating my site to Craft 3, and it's frustrating to have to pay for LinkIt when all I need is a simple conditional. I guess I could write my own plugin. Really hoping this happens. |
Beta Was this translation helpful? Give feedback.
-
@mortscode Have you tried https://github.com/sebastian-lenz/craft-linkfield ? |
Beta Was this translation helpful? Give feedback.
-
Frick @daltonrooney. MAGIC!! |
Beta Was this translation helpful? Give feedback.
-
What do conditionals have to do with LinkIt / Link ? |
Beta Was this translation helpful? Give feedback.
-
It’s currently planned for v4. In the meantime you can use Reasons. |
Beta Was this translation helpful? Give feedback.
-
Not supported within a Matrix field, I am trying to recreate ACF for my clients and without this it is very hard to get them to pay for a CMS. 👎 Is there a roadmap for v4 that I can see what sort of date we are aiming at? I thought I read somewhere v4 is not planned and that features will just come to new 3.x versions instead? |
Beta Was this translation helpful? Give feedback.
-
We’re working on publishing a roadmap; will update this when it’s out there. Timing-wise we’ll have more to say in a couple months at our Dot All conference. |
Beta Was this translation helpful? Give feedback.
-
Considering this issue first started as a feature request in 2015, I wouldn't hold my breath @JshGrn. That being said you can probably get around needing real conditionals several different ways. The plugin @daltonrooney recommended is one we use and it works well and there is another field called LinkIt which also works super well. Both of those plugins let you define custom link text and select links from a long list of sources and for most circumstances the single field can easily power your entire button code. If you have other needs for conditionals we would all be happy to brainstorm solutions! |
Beta Was this translation helpful? Give feedback.
-
@theskyfloor Yep, not holding breath... looks like a good plugin. I am yet to try it as I ended up doing it in a Neo field, although I think I will give that plugin a go as Neo is a bit heavy for my purpose. It is bonkers that 6 years on its still not something added, I don't understand why its not a priority as people will be finding it hard to migrate from ACF without it.... with this... more people would migrate and therefore 1) more people would be actively developing within Craft and 2) more people would be paying licences when more people use Craft... Thanks for the solutions all, hope it also helps someone else looking for conditionals on the same topic.... Will eagerly keep ears and eyes open for Dot All. |
Beta Was this translation helpful? Give feedback.
-
It hasn’t happened yet because to do it right (in a non-hacky way), there are some foundational changes we need to sort out. Certainly a high priority feature for us, though, so we will get there. |
Beta Was this translation helpful? Give feedback.
-
I understand that completely, but 6 years is quite the length of time :)!! I am glad it is a high priority feature as I have LOTS of sites I want to bring over to Craft and I just cant justify it without ACF, as hacky as it is. |
Beta Was this translation helpful? Give feedback.
-
Patience please! It’s not like we’ve been sitting around idly for 6 years; at any given time there are 500-1K open feature requests we are working through. We do our best to prioritize based on demand, impact, and complexity. Sorry we haven’t gotten to this particular one yet, but again, we’ll get it in eventually. |
Beta Was this translation helpful? Give feedback.
-
I think people forget what life was like before Craft sometimes... and how far it comes with every update! ;) |
Beta Was this translation helpful? Give feedback.
-
No I completely understand the work rate, its just this seems like it would bring in a lot more revenue of licences from people that just cant bite the bullet without ACF 👍 I do appreciate the updates, work and effort but this couldn't be a higher priority for me and my ~200 WordPress clients I want to migrate to Craft. |
Beta Was this translation helpful? Give feedback.
-
If it comes down to just this one feature holding you back, I consider that a huge success on our part that we have generally been making the right calls :) |
Beta Was this translation helpful? Give feedback.
-
Conditional fields (and tabs) have been added for Craft 4 🎉 (#10300) |
Beta Was this translation helpful? Give feedback.
-
not sure if this is the place to comment for a feature request for condition fields, but for a multisite setup can conditional fields be based on siteID? If not, this would be awesome. For instance, I have an article channel and the category that should be used is totally dependent on the site (i know categories may be gone in the future, I hope not) .... all other fields are the same. |
Beta Was this translation helpful? Give feedback.
-
Are there plans to add Matrix field/block conditionals too? |
Beta Was this translation helpful? Give feedback.
-
Craft 4.6.0 is out now with expanded support for live conditional fields. Now fields will automatically show/hide within asset edit pages, and all element slideouts, without needing to resave. (#14115) In Craft 5, full-page user edit forms get live conditional field support as well. |
Beta Was this translation helpful? Give feedback.
Conditional fields (and tabs) have been added for Craft 4 🎉 (#10300)