Can you implement hook to override default wrapping with "- " and " -" of the empty option on select box?

Comments

guschilds’s picture

Status: Active » Closed (works as designed)

Hey rusnis,

A hook is already in the module that can be used to accomplish this, hook_webform_hints_element_alter().

For example, if you just wanted the empty option to be the element's title and not include the surrounding "-"s, you can do:

/**
 * Implements hook_webform_hints_element_alter().
 */
function mymodule_webform_hints_element_alter(&$element, &$required_label) {
  if ($element['#type'] == 'select') {
    $element['#empty_option'] = $element['#title'];
  }
}
wjhessels’s picture

Great! And if you want the required marker with it, when it is required? title *

abaier’s picture

I achieved the placement of the required marker like this:

function mytheme_webform_hints_element_alter(&$element, &$required_label) {
  if ($element['#type'] == 'select') {

    if (!empty($element['#required'])) {
      $element['#empty_option'] = $element['#title'] . $required_label;
    } else {
      $element['#empty_option'] = $element['#title'];
    }

  }
}