Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Switch not working in blueprints

admin form

Solved by Vadym View solution

Started by Aleksandr 10 months ago · 12 replies · 122 views
10 months 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
10 months ago

Could you share the show_on property documentation?

10 months ago

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

10 months ago

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

10 months 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.

10 months ago

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

10 months 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.

10 months ago

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

Can't this be easily achieved with conditional?

10 months 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
10 months 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 😅

10 months 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, 5 years ago
13 1136 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 61 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 135 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 110 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 129 7 months ago