You are here

function webform_expand_select_or_other in Webform 7.4

Same name and namespace in other branches
  1. 6.3 components/select.inc \webform_expand_select_or_other()
  2. 7.3 components/select.inc \webform_expand_select_or_other()

Process function to ensure select_or_other elements validate properly.

1 string reference to 'webform_expand_select_or_other'
_webform_render_select in components/select.inc
Implements _webform_render_component().

File

components/select.inc, line 456
Webform module multiple select component.

Code

function webform_expand_select_or_other($element) {

  // Disable validation for back-button and save draft.
  $element['select']['#validated'] = TRUE;
  $element['select']['#webform_validated'] = FALSE;
  $element['other']['#validated'] = TRUE;
  $element['other']['#webform_validated'] = FALSE;

  // The Drupal FAPI does not support #title_display inline so we need to move
  // to a supported value here to be compatible with select_or_other.
  $element['select']['#title_display'] = $element['#title_display'] === 'inline' ? 'before' : $element['#title_display'];

  // If the default value contains "select_or_other" (the key of the select
  // element for the "other..." choice), discard it and set the "other" value.
  if (is_array($element['#default_value']) && in_array('select_or_other', $element['#default_value'])) {
    $key = array_search('select_or_other', $element['#default_value']);
    unset($element['#default_value'][$key]);
    $element['#default_value'] = array_values($element['#default_value']);
    $element['other']['#default_value'] = implode(', ', $element['#default_value']);
  }

  // Sanitize the options in Select or other check boxes and radio buttons.
  if ($element['#select_type'] == 'checkboxes' || $element['#select_type'] == 'radios') {
    $element['select']['#process'] = array_merge(element_info_property($element['#select_type'], '#process'), array(
      'webform_expand_select_ids',
    ));
  }
  return $element;
}