Required fields in conditional field context

Hi all,
i’m looking for a way to create a dependency between a toggle and other components.
If the toggle is true then other fields should be required: true.
The best solution would be: if the toggle is set to true, the whole area will slide out, is this possible?

thx for help!

We have conditional fields since v3.1. You can set that certain fields are only shown if a toggle value is true.

:wink: great timing!

thx alot

one thing: “when toggle” = true seems not to work with required fields.
I have to fill those fields also when toggle = false, am i right?

That’s one of the things I wanted to check out and haven’t come round to yet. It might well be that it doesn’t work if the fields are required.

Can’t think of a workaround at the moment.

Yes, required fields are always required, displayed or not. So if you hide Fields through conditions they shouldn’t be required.

Then we need conditional attributes:

text:
  type: text
  required:
    when:
      toggle: true
  when:
    toggle: true

Or automatically unset the required attribute when condition is false.

text:
  type: text
  required:
    when:
      toggle: true
  when:
    toggle: true

this code works ?
I’m tryng to show a field only if the toggle is on but the required validation isnt working

In the end it was implemented as

text:
  type: text
  required: true
  when:
    toggle: true

If this doesn’t work in current versions, then I guess that would be a bug.

1 Like

Thanks!
that works !

Can anybody confirm, that this still works? I run a website with Kirby 5.1.4 and and I can’t get this to work properly

Hm, seems to work fine. What is your issue?

1 Like

Thank you very much, Sonja. Then, I have to look deeper into the issue on my side. The field is in a field group (separate blueprint) that is displayed, when a toggle ist true. At the moment, I am getting an error message saying that the field must be filled in, even though the toggle is set to false.

Hi Sonja, thanks again for your confirmation. It works! Apparently, I wasn’t quite on the ball this afternoon.