8

Is there a way to create a CiviCRM form like this:

What would you like to eat at the event?

  • Falafel
  • Kebap
  • Other: ......................... <-- user can make a free entry here

As far as I can see, multiple choice fields in CiviCRM do not provide this functionality, or am I overlooking something? Any other ideas how to achieve this (or something similar)?

4 Answers 4

6

This has been a feature request from time-to-time, and would be a great one to submit to the Paid Issue Queue.

If you want to DIY a solution I'd suggest you create a simple textfield as your custom field, and then use jQuery to add some extra radios that hide and populate the field unless the "other" box is selected, then show the field.

1
  • If you do add this to the Paid Issue Queue please let me know as I have an interest in this subject as well. Thanks!
    – Andy Clark
    Commented Aug 12, 2015 at 13:47
4

Profile conditional ext can be used to provide this - https://civicrm.org/extensions/profile-conditionals

You dont have any UI option to build the conditions. But this can be easily done in civicrm.settings.php. The config we used for select-other field is pasted below -

  • custom_229 is the dropdown field wth options + other
  • custom_230 is the "Other" Text field.
global $civicrm_setting;
$select_other = [
  'onload' => [
    'selectors' => [
      '#editrow-custom_230' => [
        'display' => 'hide',
      ],
    ],
  ],
  'select-other' => [
    'conditions' => [
      'all_of' => [
        [
          'id' => 'custom_229',
          'op' => 'value_is',
          'value' => '7', //Other
        ],
      ]
    ],
    'states' => [
      'pass' => [
        'selectors' => [
          '#editrow-custom_230' => [
            'display' => 'show',
          ],
        ],
      ],
      'fail' => [
        'selectors' => [
          '#editrow-custom_230' => [
            'display' => 'hide',
          ],
          //Clear the text value if other is not selected in the dropdown
          '#custom_230' => [
            'value' => '',
          ],
        ],
      ],
    ],
  ],
];

//Apply the above condition to contribution page id 22, 23 and 24
$civicrm_setting['com.joineryhq.profcond']['com.joineryhq.profcond'] = [
  'contribution' => [
    22 => $select_other,
    23 => $select_other,
    24 => $select_other,
  ],
];
2
  • Regarding jitendra - fuzion comments, above "You dont have any UI option to build the conditions." (Profile Conditionals Extension)... Does anyone know if there are plans to incorporate this UI functionality into Civi? We have clients that want to be able to add conditional fields in forms "on the fly", without having to come to us each time to add to civicrm.settings.php.
    – Jennifer
    Commented May 5, 2022 at 15:48
  • if custom_229 is a radio button, in the subject-identifier-type I think we have to use 'selector' => "[name='custom_23']:checked" instead of 'id' => 'custom_229'
    – masetto
    Commented Nov 5 at 19:14
2

If you are based upon Drupal, an easy way to make something similar is to use a Webform with 2 items and a "conditionnal" : if item1 = "other" then item2 is shown

0

You don't have an option for entering a user value in Core Civi so you have to write a javascript to populate a field and you should read the value using POST and write to the respective table (custom field)

You can achieve by creating a new extension with some hooks

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.