Is there any way to set up a conditional field “when: an option is selected in type multiselect or checkboxes”?
It only works with a values, not on the condition that any value is selected. We’ll have more options in the future but currently, I don’t know what they will be.
There are already quite a few ideas here: https://github.com/getkirby/ideas/issues?utf8=✓&q=conditional
Thanks a lot!
Is it also working with structure fields?
haven’t tried that @redroses, but usually @rasteiner’s plugins are super well thought out. so i’m assuming yes! just give it a try, it’s super easy to set up!
Oh that’s very kind of you
Anyway, checkboxes, multiselect and structure fields are use cases I definitely want to support. The exact query syntax would change depending on what exactly you need (e.g. “show when all of these boxes are checked” is different from “show when some of these boxes are checked”).
Ping me if it doesn’t work
This is my use case for a structure field:
fields:
inhalte:
label: Schwerpunkt
type: structure
min: 1
max: 1
required: true
fields:
reflex:
label: Reflexion
type: range
step: 5
min: 0
max: 100
default: 0
tooltip:
after: %
stille:
label: Stille
type: range
step: 5
min: 0
max: 100
default: 0
tooltip:
after: %
koerper:
label: Körper
type: range
step: 5
min: 0
max: 100
default: 0
tooltip:
after: %
kreativ:
label: Kreativität
type: range
step: 5
min: 0
max: 100
default: 0
tooltip:
after: %
warning:
type: info
label: "Warnung zu o.g. Schwerpunkt"
theme: negative
text: Die Summe aller Anteile muss **100%** ergeben – bitte nochmal prüfen!
whenQuery: inhalte ::map($.value) < 100 # this is not working of course
Any hint would be great, thank you!
For a sum of all items in the structure you would need some kind of reduce
or reduceRight
equivalent. And in fact I currently don’t have that in the syntax.
But I think it’s a valid use case. I’ll just have to come up with a syntax that’s easy enough to read (at least), but without shooting myself in the foot by limiting future features. Simplicity is complex.
PS: actually, if this is your exact blueprint and there’s always exactly 1 item in the structure you could probably have this query now:
(inhalte[0].reflex + inhalte[0].stille + inhalte[0].koerper + inhalte[0].kreativ) != 100
Your query works and I´m super happy
Thank you, @rasteiner, for your great plugin and support!
Just on a side note: I guess, outputting a warning for users might in most cases be enough, but if you really want to enforce it, a pre-update hook or a custom validator might be an additional safety net.