Skip to content

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions