0

I made a field in text list format with radio button widget and I want to remove the N/A option, but my field must be not required.

I tried this code without success.

function mymodule_element_info_alter(array &$types) {
  if (isset($types['radios'])) {
    $types['radios']['#process'][] = 'remove_radio_na';
  }
}

function remove_radio_na($element) {
  if ($element['#field_name']=='field_align_image') {
    unset($element['_none']);
  }
  return $element;
}

Do you have an idea on how I can solve my issue?

3
  • What does “without success” mean?
    – cilefen
    Aug 26, 2022 at 11:25
  • 1
    If you remove the "N/A" option and the user clicks a radio button (thereby setting it by mistake), it will be impossible for that user to deselect the radio button, effectively making the radio button required (if the user makes a mistake). This is horrible usability. Aug 26, 2022 at 11:28
  • I usually work around this scenario by using a <select> element instead.
    – sonfd
    Aug 26, 2022 at 11:50

0

Your Answer

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

Browse other questions tagged or ask your own question.