billythekid / conditional-fields

Craft plugin to only use fields if certain conditions (other field values) match
MIT License
12 stars 1 forks source link
abandoned

NOTE:

This plugin was a stop-gap measure. Mats has ported Reasons for Craft 3 along with this note in the Craft Discord:

I decided to finally port it from Craft 2, primarily to make it easier to upgrade Craft 2 sites using it. I'd avoid using it for new Craft 3 builds, since there's no guarantee it'll be possible/feasible to migrate Reasons conditionals to core conditionals, once Craft 4 drops On the other hand, "soon" is a very relative term... Back when 3.0 released, I'd never guessed it'd take 3-4 years before field layout conditionals would make it to core. Also, we still don't actually know when Craft 4 is coming out :slight_smile:

Brandon also added:

There's been a change of plans re v4 in light of … everything. Originally v4 was to be our main focus this year, but now we don't think the timing is right for a breaking update like that. So we're working to add as many of the v4 features into v3 as we can w/out breaking things, hopefully including conditional fields. It's a bit more slow going because brownfield, but we think it's the right call.

So unless you really need conditional fields I'd suggest waiting for it to come into core. If you really really need them, first use Reasons and only if you need the dumbest implementation use this. You've been warned!

Conditional Fields plugin for Craft CMS 3.x

Conditional Fields Overview

Show or hide fields or tabs of fields based on the value of other fields. PRs gratefully received.

Easy now, this is probably not all you hoped it would be when you saw it was released! That said, please post any issues you're having and I'll check them out.

Conditional field layouts are coming to Craft CMS version 4 core. Craft CMS version 2 had the Reasons plugin but there's nothing working for Craft 3 at the moment.

Reasons is back! I strongly suggest using that plugin instead of this one!

This is a very simple, very dumb, implementation of a way to get conditional field layouts in your entries etc.

If you need something complex it's almost certainly not possible with this plugin, but if you just need to show and hide some fields based on simple selections, like light switches, give it a whirl.

Requirements

This plugin requires Craft CMS 3.4.10 or later. It may work on earlier (^3.0) versions but I've not tested it. I haven't restricted installation to 3.4.10 so give it a go!

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

    cd /path/to/project
  2. Then tell Composer to load the plugin:

    composer require billythekid/conditional-fields
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Conditional Fields.

Using Conditional Fields

This plugin adds a new available field type called "Conditional".

Creating a conditional field to show/hide fields:

Creating a conditional field for fields

Creating a conditional field to show/hide tabs:

Creating a conditional field for tabs

To check for an entry in an entry field, use 'contains' and put the entry ID as the value.

NOTE: Chances are that this won't work inside a matrix block or other complicated stuff. Keep it simple.

Once your conditional field is created you can drag it in to any field layouts you want it to work in.

adding a conditional field to a field layout

The field itself is invisible to your layout. There are no settings or values to be saved in the layout view, we're just adding functionality so we hide it.

Example of showing/hiding fields:

Layout view showing a matching fields condition Layout view showing a non-matching fields condition

Example of showing/hiding tabs:

Layout view showing a non-matching tabs condition Layout view showing a matching tabs condition

Dos and Don'ts

Do…

Don't…