Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional fields and tabs #10300

Merged
merged 9 commits into from
Jan 3, 2022
Merged

Conversation

brandonkelly
Copy link
Member

@brandonkelly brandonkelly commented Jan 3, 2022

Description

The field layout designer has been updated to open tab and layout element settings in slideouts, which now include two new settings:

  • Current User Condition – determines when the tab/field should be visible based on the logged-in user.
  • [Element type] Condition (e.g. “Entry Condition”) – determines when the tab/field should be visible based on the element being edited.

Screenshot of a field layout designer, with a custom field’s settings slideout open, showing the two new condition settings

Edit Entry pages will show/hide tabs and fields as edits are being made, thanks to draft autosaves. Other forms will only factor in the conditions when they are first rendered.

Related issues

@linear
Copy link

linear bot commented Jan 3, 2022

@mmikkel
Copy link
Contributor

mmikkel commented Jan 3, 2022

Took this for a quick test drive, and at first glance everything looks and works great. Thanks for finally getting this much-wanted feature into core!

That said, there's a couple of improvements I'd love to see in the final release 😅

  1. There should probably be some kind of visual cue in the FLD, for layout elements with conditions – similar to how required fields get a * next to their label.

    Editing complex layouts with multiple conditionals is likely going to be unnecessarily frustrating, if it's not possible to tell at a glance which elements have conditions or not (i.e. without opening the elements' settings slideouts).

    The Reasons plugin solved this by adding a simple, dashed outline to elements with conditions. I always thought this was a decent way to communicate that a particular element would only conditionally display, but I'm sure there are better/clearer ways to achieve the same thing.

    CleanShot 2022-01-03 at 23 42 06@2x
  2. The ability to create simple "Empty / Not empty" conditions for relational fields would be massively useful.

@brandonkelly brandonkelly merged commit 1cfd481 into 4.0 Jan 3, 2022
@brandonkelly brandonkelly deleted the feature/dev-85-conditional-fields branch January 3, 2022 23:08
@brandonkelly
Copy link
Member Author

@mmikkel Both good suggestions. Can definitely do an empty/not-empty relational field condition rule.

@brandonkelly
Copy link
Member Author

Just added an operator menu to relational field conditions, with the options “has a value”, “is empty”, and “is related to”. The first two are available in all contexts; “is related to” is only available for conditions that don’t need to be stored in the project config (so… element index filters).

@brandonkelly
Copy link
Member Author

brandonkelly commented Jan 6, 2022

Annnnd now layout elements with conditions get a special border:

Snippet of a field layout designer, showing that two of the included layout elements have a special border, indicating that they have conditions set on them

@mmikkel
Copy link
Contributor

mmikkel commented Jan 6, 2022

Annnnd now layout elements with conditions get a special border

That is awesome 👏 Thank you!

@andrewfairlie
Copy link

andrewfairlie commented Jan 14, 2022

I've not been able to install this yet, so apologies for asking what may be obvious, but I'm thinking ahead to a future project I have coming up. With this solution is it possible to show/hide fields based on file type? For example: if it's an image asset show "Alt Text", but if it's a PDF don't?

Edit: Noticed this comment which implies it's possible #10302 (reply in thread)

@brandonkelly
Copy link
Member Author

Yep!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants