Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Form - conditional field

Started by Dean Bateman 9 years ago · 1 replies · 2412 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 Anna, 2 days ago
2 53 16 hours ago
Forms & Blueprints · by Anna, 3 days ago
7 82 16 hours ago
Forms & Blueprints · by Anna, 1 week ago
5 186 6 days ago
Forms & Blueprints · by TomW, 1 month ago
3 379 1 month ago
Forms & Blueprints · by Japhy, 2 months ago
2 595 2 months ago