diff --git a/src/Plugin/WebformElement/OptionsBase.php b/src/Plugin/WebformElement/OptionsBase.php index bf72f98b8..bcbd16075 100644 --- a/src/Plugin/WebformElement/OptionsBase.php +++ b/src/Plugin/WebformElement/OptionsBase.php @@ -236,6 +236,13 @@ abstract class OptionsBase extends WebformElementBase { unset($element['#default_value']); } + // If the #default_value of a radios element is not a value of #options, + // we need to unset the #default_value to prevent the below error. + // 'An illegal choice has been detected'. + if ($element["#type"] == 'radios' && isset($element['#default_value']) && !array_key_exists($element["#default_value"], $element["#options"])) { + unset($element['#default_value']); + } + // Process custom options properties. if ($this->hasProperty('options__properties')) { $this->setElementDefaultCallback($element, 'process');