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

Form - conditional field

Started by Dean Bateman 9 years ago · 1 replies · 1678 views
9 years ago

i am trying to set up a form, that when a checkbox is ticked, it displays another field.

I think this is what the conditional field is for.
i have tried it in a form.md page with a checkbox and its id set

condition: "id ? 'false' : 'true'"

it only displays when i set the default, it doesnt live update when toggled

further to this it completely breaks a modular page.

am i using this correctly?

YAML
    - type: conditional
      condition: 'true'
      classes: overlay bottom

      fields:
          field-a:
              label: New Field A
              type: text

          field-b:
              label: New Field B
              type: text
9 years ago

Hi,

The conditional field will only evaluate the condition when the page is generated, not dynamically.
Condition has to be a ternary twig condition.
You therefore have to use javascript to achieve what you want.

Hope it helps!

👍 1

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1135 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 60 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 132 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 108 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 127 7 months ago