Problem/Motivation
I'm having difficulty controlling the visibility of a field-set based on a toggle field. It works fine with a checkbox or radio field. I've tried testing against the value of "Yes" or "YES" for the toggle and it doesn't work. I only want to display further software-related fields if the customer says that their product includes software. What am I missing? Here's the conditional fieldset with my various trigger experiments.
software_platform:
'#type': fieldset
'#title': 'Software Platform'
'#title_display': before
'#states':
visible:
- ':input[name="software"]':
value: 'YES'
- or
- ':input[name="software_check"]':
checked: true
- or
- ':input[name="software_radio"]':
value: 'Yes'
Question 4: Although I removed it from this test form, does the Javascript code handle cases where the element with the conditions is nested inside of a flexbox or any number of containers and it's referencing a checkbox that is outside of the conditioned element's containment hierarchy?
Comment | File | Size | Author |
---|---|---|---|
#3 | conditional_visibility-2878397-3.patch | 772 bytes | jrockowitz |
|
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe below form replicates the issue.
Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedI committed the patch. Please download the latest dev release to review.
Comment #6
kirkilj CreditAttribution: kirkilj commentedQuestion #1: I downloaded this version. Is it the correct one?
but this test form still fails, even with the normal checkbox.
Question #2: When I'm dealing with Term Checkboxes on a vocabulary, how can indicate whether they should be all checked or not?
Question #3: I noticed that some element names below are truncated, and values referenced in the conditions of other elements have array indices after them. Can you enlighten me what's happening here?
Question 4: Although I removed it from this test form, does the Javascript code handle cases where the element with the conditions is nested inside of a flexbox or any number of containers and it's referencing a checkbox that is outside of the conditioned element's containment hierarchy?
Comment #7
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedQuestion #1: Make sure to clear your browser's cache. Toggle buttons #states is working for me using Chrome.
Question #2: You probably need to write a custom jQuery selector that targets all term checkboxes.
Question #3: Webform's #states API integration targets the :input[name] which vary depending on the type of input. For example, checkboxes use element_key[option_value] as the input name for each checkbox.
Question #4: #states API allows you to use any selector. @see https://www.lullabot.com/articles/form-api-states