Conditional Fields and Term Reference Tree taxonomy: two small bugs & how to fix them
I'm working on a site that uses Conditional Fields and Taxonomy Term Reference Tree Widget. Conditional Fields allows you to show certain fields in your content type only if other fields contain a particular value, and Term Reference Tree cleans up the UI on the backend for neater nested checkbox lists.
Today I encountered two problems when using these two modules with each other. Both were odd enough that I'm writing them up to save someone else time trolling the issue queue.
Background & Examples
This client has a very complex taxonomy structure, and has a need to show some vocabularies only when certain values are provided in other vocabularies.
Here's an example of what I'm trying to do, tags renamed to protect the innocent:
field_pet has three options: cat, rabbit, dog.
field_cat_breed has three options: Persian, tabby, Manx.
field_rabbit_breed has three options: lionhead, dwarf, lop.
field_dog_breed has three options: black lab, Australian shepherd, Chow.
I only want to show field_cat_breed if field_pet is set to cat, because only cats should have a cat breed. field_rabbit_breed should only be shown if the pet is a rabbit. field_dog_breed should only be shown if it's a dog.
Unlike the examples above, the vocabularies on my site have a deep nested taxonomy, so we implemented Term Reference Tree on all the vocabularies to give them nice nested checkboxes.
Problem 1: Conditional Fields Are Always Shown
The first problem I ran into was that field_cat_breed, field_rabbit_breed, and field_dog_breed were always shown, no matter what value I picked for field_pet -- or even if field_pet was completely empty.
Problem: It appears that Conditional Fields can't process input from Term Reference Tree. I didn't find a bug report to this effect, but found that if I switched the dependee (field_pet) from Term Reference Tree to a core widget type, the problem went away.
Solution: Go to your content type > Manage Fields. Find field_pet and click edit. Click Widget Type. Change it to checkboxes/radio buttons.
Problem 2: Tags Aren't Saved on the Node
Having solved Problem #1, I set field_pet to rabbit and then set field_rabbit_breed to lionhead. I saved the node. While other tags not related to this dependency did show up (e.g. field_color), "lionhead" was stubbornly missing. I reopened the node and checked. It hadn't saved. I tried this multiple times with a variety of different tweaks, and sometimes "rabbit" did save, sometimes it didn't.
This post in the Conditional Fields issue queue gave me the answer. I had been setting my dependency like this:
Dependent: field_rabbit_breed
Dependee: field_pet
Values input mode: Insert value from widget...
[Check the box for "rabbit".]
This is much more convenient but apparently has a bug. Instead, I needed to set it manually. I checked the ID of the "rabbit" tag -- let's say 12 -- and set my dependency like this:
Dependent: field_rabbit_breed
Dependee: field_pet
Values input mode: All of these values (AND)...
Set of values: 12
I saved that dependency, added similar dependencies for field_dog_breed and field_cat_breed, went back to my node, and selected "rabbit" and "lionhead" again. It saved with no problem.