Making a Conditional Fields based on Taxonomy value #7546
-
I am trying to make a field conditional on taxonomy category selection. But can't get it to work, the fields just stay hidden no matter what i select in the taxonomy select field. Here is my yaml file: sections:
main:
display: Main
fields:
-
handle: title
field:
type: text
required: true
validate:
- required
-
handle: content
field:
type: markdown
localizable: true
sidebar:
display: Sidebar
fields:
-
handle: slug
field:
type: slug
localizable: true
-
handle: date
field:
type: date
required: true
validate:
- required
-
handle: lesson_type
field:
type: terms
taxonomies:
- lesson_type
display: 'Lesson Type'
mode: select
instructions_position: above
listable: hidden
visibility: visible
create: false
validate:
- required
max_items: 1
-
handle: video
field:
display: Video
type: video
icon: video
listable: hidden
instructions_position: above
visibility: visible
validate:
- required
- sometimes
if:
lesson_type: 'equals Video'
-
handle: audio
field:
mode: list
container: files
restrict: true
allow_uploads: true
show_filename: true
max_files: 1
display: Audio
type: assets
icon: assets
listable: hidden
instructions_position: above
visibility: visible
validate:
- sometimes
- required
if:
lesson_type: 'equals Audio'
title: Lesson |
Beta Was this translation helpful? Give feedback.
Answered by
jasonvarga
Feb 15, 2023
Replies: 1 comment 1 reply
-
The value the condition uses is the javascript value, which is an array of term ids. A term id is the taxonomy handle and the term slug combined with e.g. So you should do this: if:
- lesson_type: 'equals Video'
+ lesson_type: 'contains lesson_type::video' |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
bomshteyn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The value the condition uses is the javascript value, which is an array of term ids.
A term id is the taxonomy handle and the term slug combined with
::
.e.g.
['lesson_type::video']
So you should do this: