3

I am converting some D7 forms and came across a problem this week with adding conditionals. On one form, I display a text field if one of a set of 8 check boxes is checked. It's the common form usecase to collect more information if the 'Other' choice is also selected.

enter image description here

When this is added to the webform automatically it is added as type 'civicrm_options'. To add a conditional, I went to the text field and selected that I wanted it to be Visible if the 'Other' option was selected: enter image description here

Try as I might I could not get this to fire. I made a test 'Table Select' element to see if I could mimic the behaviour and it worked fine... Looking a the source of the condition, the penny dropped:

This is the source that is produced by following what the UI allows you:

 visible:
  ':input[name="civicrm_1_case_1_cg43_custom_426"]':
    value: '6'

This is the source that I got from my test Table select element:

 visible:
  ':input[name="choice_multi[4]"]':
    checked: true

So the work around for me was to add the same syntax:

visible:
  ':input[name="civicrm_1_case_1_cg43_custom_426[6]"]':
    checked: true

This gives you this final result when it is viewed through the UI:

enter image description here

It perhaps should have been obvious, but maybe just an issue with the Webform CiviCRM integration. Anywway, I hope this helps others!

An open question - I tried changing the type of my CiviCRM element from civicrm_options to tableselect. It all seemed to work fine and values seemed to save OK. I am nervous about making those sorts of changes as it is only possible to do this sort of thing through the build YAML source. If it not dangerous, it might be far easier as then you get a far easier interface to do the conditionals.

4
  • Great work! I needed this today, thanks so much!
    – dtw
    Dec 8, 2023 at 14:34
  • Cheers, but but check out KatinG's comment re changing the type to checkboxes as you may find this neater!
    – ChumKui
    Dec 10, 2023 at 15:59
  • I did do that on a few fields but "CiviCRM Options" (I think) is dynamically linked to the dbase, so will reflect any new options added. Switching to checkboxes becomes a static list, which is not always ideal.
    – dtw
    Dec 12, 2023 at 7:44
  • True, if you need them to dynamicaly update, you have to use CiviCRM Options. I tend to version control on one set of options, but if you need it to update as CiviCRM options change, then yes my original solution is the best for you!
    – ChumKui
    Dec 20, 2023 at 13:24

1 Answer 1

2

I would retype from CiviCRM Options -> Checkboxes. Then not only are conditionals way easier, you will also get some nice layout options -> e.g. 2 columns or 3 columns.

3
  • HI Karin - Many thanks. Just to be sure, you mean you mean change the actual type in the YAML source from 'civicrm_options' to 'checkboxes'. I ask as you cannot add an element using the Webform module called 'checkboxes', you only get 'tableselect'. The Form API has this but I'll be honest and do not understand the difference between the two. It is good to know that these types can be changed without distructive changes to CiviCRM data
    – ChumKui
    Jul 5, 2023 at 9:42
  • You can actually just hit Edit on the element and then re-type from CiviCRM Options -> to Checkboxes [most common re-typing are available via the UI]. Jul 7, 2023 at 13:52
  • That really helpful Karin - many thanks, I'll give it a go
    – ChumKui
    Jul 7, 2023 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.