Skip to content

Conditional fields: can't match on two options of a select field #759

@sauerbraten

Description

@sauerbraten

Using the current if_any construct, it's impossible to match on multiple options of a select field. For example:

-
    handle: type
    field:
        type: select
        options:
            opt1: Type 1
            opt2: Type 2
            opt3: Type 3
-
    handle: some_detail
    field:
        type: toggle
        if_any:
            type: opt1
            type: opt2

The blueprint above is invalid because of the duplicate type key inside the if_any. Thus, it's impossible (using if_any) to make the some_detail field show up when "Type 1" or "Type 2" are selected, but have it hidden when "Type 3" is selected.

As a workaround, using a custom method works:

Statamic.condition('type1OrType2', values => ['opt1', 'opt2'].includes(values.type));
-
    handle: type
    field:
        type: select
        options:
            opt1: Type 1
            opt2: Type 2
            opt3: Type 3
-
    handle: some_detail
    field:
        type: toggle
        if: type1OrType2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions