ideas icon indicating copy to clipboard operation
ideas copied to clipboard

FR: Option to let conditions also work with fieldsets.

Open SoofNikki opened this issue 4 years ago • 15 comments

It would be really helpful if it is also possible to set a condition for a fieldset in the CMS. It is now only possible on normal fields.

Example: If toggle = true, show this fieldset. If toggle is false, show another fieldset.

When I try this code my CMS blueprint will eventually override this piece of code when I save it.

 -
        import: typing_header
        if:
          animated_header: 'equals true'

SoofNikki avatar Jan 27 '21 13:01 SoofNikki

A workaround for this would be to add the conditions to each field inside the fieldset.

jasonvarga avatar Mar 01 '21 20:03 jasonvarga

Bumping because I don't believe that workaround is suitable. A fieldset could be (and likely is) used in multiple places. Sometimes the condition that would be checked in one blueprint differs from another.

In my case, I use a fieldset for a specific component that can be used in content, so it is linked in Bard as a set. But also may be used outside of content, so it is linked in the blueprint for the page. I would like it to conditionally only show if a particular toggle were on in the page, but unconditionally show if it is added as a set to bard.

shawnsquire avatar Mar 27 '21 04:03 shawnsquire

I just spent about 30min going down a rabbit hole trying to figure out if something was possible and it appears it isn't - I thought I would share here in case relevant.

Basically I'd like the ability to hide a set in a replicator without "removing it from play".

The use-case is I have 10 variations of a hero component with slightly different fields (I know I can use conditionals but hear me out)...

If I was to create sets for each of the variations then hide all but the default hero, I could add a select element with the handle type to allow dynamically changing the set type, including to the hypothetical non-visible ones.

demo

Here is a demo

The result is a pretty nice experience for users!!! You can see no data is lost when switching. Fieldsets mean configuration is rather DRY and it's easier to modify than conditionals.

Unfortunately you CAN'T hide a set (correct?) so this means, 10 variations in the replicator... which is what I wanted to avoid. Back to a select that isn't named type and conditionals for now.

But if we could add conditions to a set (or just hide them) I can see this having potential.

MadeByMike avatar Apr 19 '21 00:04 MadeByMike

Yes to this!

Accidentally duplicated this – here’s my two cents of how it would be handy:

https://www.loom.com/share/df6f8dfac42d4ada97683ed778916f0e

dave-smyth avatar Nov 22 '22 11:11 dave-smyth

This would be a really helpful when working with fieldsets. 🚀

o1y avatar Jan 09 '23 11:01 o1y

any news on this? or what is the current workaround?

Bergrebell avatar May 23 '23 09:05 Bergrebell

My workaround is wrapping each imported fieldset into a Grid with max_rows and min_rows set to 1, hide_display to true, reorderable and fullscreen to false

patrickhoehn avatar Aug 30 '23 18:08 patrickhoehn

@jasonvarga Any idea when this will be fixed? Because the workaround you provided isn't a full proof option.

justkidding96 avatar Sep 11 '23 09:09 justkidding96

No ETA at the moment.

jasonvarga avatar Sep 11 '23 14:09 jasonvarga

@jasonvarga Currently, I am already programming on a solution. The only problem I am running into, is storing the conditions within the CP (Vue JS). Is this easy for you to make? Because I can already add a condition in the YAML files which the back-end code reads. See screenshot below for an example YAML structure. Scherm­afbeelding 2023-09-11 om 19 37 36

Update: I've created a pull request for this request: https://github.com/statamic/cms/pull/8690

justkidding96 avatar Sep 11 '23 17:09 justkidding96

+1, tbh we are urgently missing this in some projects.

simply adding the conditions to each field in the fieldsets is not a workaround which I feel is sufficient – imho a fieldset should be agostic to the context it will be referenced in :)

mnlmaier avatar Nov 13 '23 10:11 mnlmaier

Would be helpful indeed, missing this a lot.

GertTimmerman avatar Apr 11 '24 08:04 GertTimmerman

I added some additional ideas in another discussion (before I found this issue): https://github.com/statamic/cms/discussions/9836#discussioncomment-9477079.

Deals with fieldsets, sections, groups and the idea to add the logic to a controlling field instead to the reacting fields.

I have the exact same problem. When I use a fieldset in a blueprint, there is no option to apply the usual conditional show or hide logic. The same is true for sections.

To use a group field to wrap a fieldset or a field adds unnecessary complexity and somewhat thwarts the purpose of fieldsets to make using fields easier, and it prevents fields/fieldsets from being moved around easily individually because they are stuck in a group. (Group fields also add superfluous labels on the blueprint, especially if used for just one field or a fieldset with just one field.)

If it were possible to give them both (fieldsets and sections) access to the conditional view/hide logic, that would be a big plus in terms of usability!

I'm not sure if it's technical feasible, but wouldn't it be better if we had an option in the steering/controlling field to decide which other fields (identified by their handles) should be shown or hidden? By way of a list of handles?

For example: If you have a toggle, offer a select option there to create a list of handles of other fields, fieldsets and sections which should be conditionally hidden.

That would have the added benefit that it's no longer necessary to duplicate the same kind of logic in a bunch of fields (and no, putting them in groups is not always an option if they are sprinkled throughout the blueprint.)

jensolafkoch avatar May 18 '24 13:05 jensolafkoch

+1

ssyberg avatar Sep 06 '24 18:09 ssyberg

+1

justkidding96 avatar Sep 09 '24 15:09 justkidding96