I have been building a questions using the method shown at the bottom of the entry on Multiple Choice Lists, here: https://docassemble.org/docs/fields.html#field%20with%20choices (i.e. by specifying a list of dictionaries in a code
block following a choices
declaration.
It seems many properties can be held in the dictionary - I'm wondering if there's a way to use hide if
/ show if
in the same way (i.e. by adding a key-value pair to the relevant dictionary(ies)? If so, I haven't been able to crack it. I think it should be possible, because as far as I can tell each choice for any multiple choice question is a python dictionary, but I'd love to know if it's possible, how?
I.E. expanding on the example in the docs:
question: |
What type of shoes do you wear?
field: target_variable
choices:
code: |
[{'sneakers': "Sneakers",
'help': "Comfortable shoes.",
'css class': "sneakers",
'color': "secondary"},
{'sandals': "Sandals",
'help': "For summer.",
'css class': "sandals",
'color': "danger",
'hide_if':"shopping_for_arctic_attire'}, # something like this?
{'clogs': "Clogs",
'help': "For hippies.",
'css class': "clogs",
'color': "warning",
'show_if': "needs_arch_support"}, # something like this?
{'other': "Other",
'default': True,
'help': "Because the other types suck.",
'css class': "othershoe",
'color': "success"}]
This feature has been added in version 1.4.42 of docassemble. The syntax for your example would be:
{'sandals': "Sandals",
'help': "For summer.",
'css class': "sandals",
'color': "danger",
'show if': not shopping_for_arctic_attire},