diff --git a/src/Element/YamlFormEntityCheckboxes.php b/src/Element/YamlFormEntityCheckboxes.php
index dca55a1..6b565a4 100755
--- a/src/Element/YamlFormEntityCheckboxes.php
+++ b/src/Element/YamlFormEntityCheckboxes.php
@@ -18,9 +18,7 @@ class YamlFormEntityCheckboxes extends Checkboxes {
    * {@inheritdoc}
    */
   public static function processCheckboxes(&$element, FormStateInterface $form_state, &$complete_form) {
-    if (!isset($element['#options'])) {
-      $element['#options'] = self::getOptions($element['#target_type'], $element['#selection_handler'], $element['#selection_settings']);
-    }
+    self::setOptions($element);
     return parent::processCheckboxes($element, $form_state, $complete_form);
   }
 
diff --git a/src/Element/YamlFormEntityRadios.php b/src/Element/YamlFormEntityRadios.php
index e2f7cd9..fb42f92 100755
--- a/src/Element/YamlFormEntityRadios.php
+++ b/src/Element/YamlFormEntityRadios.php
@@ -18,9 +18,7 @@ class YamlFormEntityRadios extends Radios {
    * {@inheritdoc}
    */
   public static function processRadios(&$element, FormStateInterface $form_state, &$complete_form) {
-    if (!isset($element['#options'])) {
-      $element['#options'] = self::getOptions($element['#target_type'], $element['#selection_handler'], $element['#selection_settings']);
-    }
+    self::setOptions($element);
     return parent::processRadios($element, $form_state, $complete_form);
   }
 
diff --git a/src/Element/YamlFormEntitySelect.php b/src/Element/YamlFormEntitySelect.php
index 55ebda5..f287282 100755
--- a/src/Element/YamlFormEntitySelect.php
+++ b/src/Element/YamlFormEntitySelect.php
@@ -18,10 +18,14 @@ class YamlFormEntitySelect extends Select {
    * {@inheritdoc}
    */
   public static function processSelect(&$element, FormStateInterface $form_state, &$complete_form) {
-    if (!isset($element['#options'])) {
-      $element['#options'] = self::getOptions($element['#target_type'], $element['#selection_handler'], $element['#selection_settings']);
-    }
+    self::setOptions($element);
     $element = parent::processSelect($element, $form_state, $complete_form);
+
+    // Must convert this element['#type'] to a 'select' to prevent
+    // "Illegal choice %choice in %name element" validation error.
+    // @see \Drupal\Core\Form\FormValidator::performRequiredValidation
+    $element['#type'] = 'select';
+
     return $element;
   }
 
diff --git a/src/Element/YamlFormEntityTrait.php b/src/Element/YamlFormEntityTrait.php
index fe9140f..4a1ce13 100755
--- a/src/Element/YamlFormEntityTrait.php
+++ b/src/Element/YamlFormEntityTrait.php
@@ -21,35 +21,45 @@ trait YamlFormEntityTrait {
   }
 
   /**
-   * Get entity references as options.
+   * Set referencable entities as options for an element.
    *
-   * @param string $target_type
-   *   The ID of the target entity type.
-   * @param string $selection_handler
-   *   The plugin ID of the entity reference selection handler.
-   * @param array $selection_settings
-   *   An array of settings that will be passed to the selection handler.
-   *
-   * @return array
-   *   An associative array of entity key and labels as options.
-   *   (e.g. array(1 => 'Node Title (1)').
+   * @param array $element
+   *   An element.
    *
    * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
    *   Thrown when the current user doesn't have access to the specified entity.
    *
    * @see \Drupal\system\Controller\EntityAutocompleteController
    */
-  public static function getOptions($target_type, $selection_handler, $selection_settings) {
-    $options = [
-      'target_type' => $target_type,
-      'handler' => $selection_handler,
-      'handler_settings' => $selection_settings,
+  public static function setOptions(array &$element) {
+    if (isset($element['#options'])) {
+      return;
+    }
+
+    $selection_handler_options = [
+      'target_type' => $element['#target_type'],
+      'handler' => $element['#selection_handler'],
+      'handler_settings' => $element['#selection_settings'],
     ];
 
     /** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface $selection_manager */
     $selection_manager = \Drupal::service('plugin.manager.entity_reference_selection');
-    $handler = $selection_manager->getInstance($options);
-    return OptGroup::flattenOptions($handler->getReferenceableEntities());
+    $handler = $selection_manager->getInstance($selection_handler_options);
+    $referenceable_entities = $handler->getReferenceableEntities();
+
+    // Flatten all bundle grouping since they are not applicable to
+    // YamlFormEntity elements.
+    $options = [];
+    foreach ($referenceable_entities as $bundle => $bundle_options) {
+      $options += $bundle_options;
+    }
+
+    // Only select menu can support optgroups.
+    if ($element['#type'] !== 'yamlform_entity_select') {
+      $options = OptGroup::flattenOptions($options);
+    }
+
+    $element['#options'] = $options;
   }
 
 }
diff --git a/src/Plugin/YamlFormElement/YamlFormEntityOptionsTrait.php b/src/Plugin/YamlFormElement/YamlFormEntityOptionsTrait.php
index 03eb298..284fee5 100644
--- a/src/Plugin/YamlFormElement/YamlFormEntityOptionsTrait.php
+++ b/src/Plugin/YamlFormElement/YamlFormEntityOptionsTrait.php
@@ -27,9 +27,7 @@ trait YamlFormEntityOptionsTrait {
    * {@inheritdoc}
    */
   public function prepare(array &$element, YamlFormSubmissionInterface $yamlform_submission) {
-    if (!isset($element['#options'])) {
-      $element['#options'] = YamlFormEntityTrait::getOptions($element['#target_type'], $element['#selection_handler'], $element['#selection_settings']);
-    }
+   YamlFormEntityTrait::setOptions($element);
     parent::prepare($element, $yamlform_submission);
   }
 
@@ -37,9 +35,7 @@ trait YamlFormEntityOptionsTrait {
    * {@inheritdoc}
    */
   protected function getElementSelectorInputsOptions(array $element) {
-    if (!isset($element['#options'])) {
-      $element['#options'] = YamlFormEntityTrait::getOptions($element['#target_type'], $element['#selection_handler'], $element['#selection_settings']);
-    }
+    YamlFormEntityTrait::setOptions($element);
     return parent::getElementSelectorInputsOptions($element);
   }
 
