Hi,
Let's say I have a form that includes a taxonomy field (check boxes of options like Red, Blue, Green.) There's a chance the users miss checking a box when submitting the form.
So when I display this taxonomy value on a template, I want to show a field label only if there's a selected option by the user like so – Color: Red. In this case, I need to conditionally display the field label. How do I set display condition on the template?
If in the case I can't conditionally check for selected option to display the label, then the second idea is to have a default selection of option. If user didn't check the box, the default selection is None. So I can display this on my template like so – Color: None. How do I set a default option for taxonomy field?
Thank you.
You have a third option:
Ensure the user selects an option on the Form already.
I elaborate on this approach here:
https://toolset.com/forums/topic/conditional-display-based-on-taxonomy-selection-in-a-cred-form/
With this approach you can, for example, hide the Submit button, if the taxonomy value isn't checked or even, a specific option.
Related to ensure there is data when you display it, this is always a good idea as well.
You can do that with HTML conditionals in the Template you display the Taxonomy chosen.
Those are explained here:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/
For Taxonomies, you'd have to use this syntax:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/displaying-taxonomies-conditionally/
There are ways to check if the post you display has any term of a taxonomy assigned (hence "is not empty"):
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/displaying-taxonomies-conditionally/#one
But also, to check the specific term assigned:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/displaying-taxonomies-conditionally/#specific
This allows you to output any text, such as labels, conditionally to whether there is such term or not.
Thanks for the reply, Beda. What you have above are the solutions I was looking for. I'll look into the details and determine which will work best for me. Again, thank you for the quick help.