Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Switch not working in blueprints

admin form

Solved by Vadym View solution

Started by Aleksandr 1 year ago · 12 replies · 600 views
1 year ago

Hello everyone, the switch for hiding/showing dependent blocks does not work for me. Both the switch and both blocks are visible. I can’t figure out the reason. Grav v1.7.49.2 - Admin v1.10.49Below is the blueprints codeThanks.
image_2025-08-29_11-44-36|690x105

YAML
title: 'Conditional Example'
'@extends':
    type: default
    context: blueprints://pages

form:
  fields:
    tabs:
      type: tabs
      active: 1
      fields:
        content:
          fields:

            # SELECTOR FIELD
            header.content_choice:
              type: select
              label: 'Content Type'
              options:
                option_a: 'Option A'
                option_b: 'Option B'
                none: 'Hide Both'
              default: none

            # OPTION A FIELDS
            header.option_a_field:
              type: text
              label: 'Option A Text'
              show_on: content_choice.option_a
              placeholder: 'Enter text for Option A'

            # OPTION B FIELDS  
            header.option_b_field:
              type: textarea
              label: 'Option B Content'
              show_on: content_choice.option_b
              placeholder: 'Enter content for Option B'

last edited 08/29/25 by Aleksandr
1 year ago

Could you share the show_on property documentation?

1 year ago

yes, i used show_on incorrectly, there is no such thing in the documentation. Thanks

1 year ago

Could you share the correct way to use it? My question isn't a solution 🙂

1 year ago

in blueprints yaml there is no concept show_on, I "invented" it. So your question - gave birth to the answer. I make a yaml generator and twig markup, that's why I got the feeling that shov_on should work.

1 year ago

I agree, but this is not a customer-friendly method))

1 year ago

show_on is a property that AI usually offers, I don’t know why it does it in Grav, but I’m sure there will be some other CMS that supports it, but it wouldn’t be bad for Grav to implement it.

1 year ago

@pmoreno:
it wouldn’t be bad for Grav to implement it

Can't this be easily achieved with conditional?

1 year ago Solution

What about Elements Field, it does exactly what is needed in this case.
@mosam, example based on your markup below :backhand_index_pointing_down:

<details>
<summary>Conditional Example</summary>

YAML
title: 'Conditional Example'
extends@:
  type: default
  context: blueprints://pages

form:
  fields:
    tabs:
      type: tabs
      active: 1
      fields:
        content:
          fields:
            header.content_choice:
              type: elements
              label: 'Content Type'
              default: none
              options:
                none: 'Hide Both'
                option_a: 'Option A'
                option_b: 'Option B'

              fields:
                option_a:
                  type: element
                  fields:
                    # OPTION A FIELDS
                    header.option_a_field:
                      type: text
                      label: 'Option A Text'
                      placeholder: 'Enter text for Option A'

                option_b:
                  type: element
                  fields:
                    # OPTION B FIELDS  
                    header.option_b_field:
                      type: textarea
                      label: 'Option B Content'
                      placeholder: 'Enter content for Option B'

</details>

👍 1
1 reply
1 year ago

I thought I saw something like that some time ago, but when I couldn't find it quickly, I figured I was imagining it 😅

1 year ago

The conditional fields require to have one more field and the field of type elements I think I remember that it had some problems to show other fields like filepicker. I don’t know, maybe having a native property in the blueprint fields that would evaluate if another field is dependent would be interesting.

👍 1

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 6 years ago
13 2070 7 months ago
Forms & Blueprints · by Hugo Oliveira, 8 months ago
0 573 8 months ago
Forms & Blueprints · by Flachy Joe, 9 months ago
9 663 9 months ago
Forms & Blueprints · by Augustus, 9 months ago
7 713 9 months ago
Forms & Blueprints · by Julien, 10 months ago
10 699 10 months ago