From 16303a2dd2e7fa7388a2ea49483dc6d67298427c Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Thu, 10 Jul 2025 16:52:12 +0200 Subject: [PATCH] MDL-85989 output: Fix choicelist when selected 0 is not first Previously, when the selected value in a choicelist was 0 but not in the first position, the behavior was incorrect. This commit fixes that issue, ensuring the choicelist behaves as expected regardless of the position of the 0 value. --- lib/classes/output/choicelist.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/classes/output/choicelist.php b/lib/classes/output/choicelist.php index 65a47919a54..4edc60867de 100644 --- a/lib/classes/output/choicelist.php +++ b/lib/classes/output/choicelist.php @@ -121,7 +121,7 @@ class choicelist implements named_templatable, renderable { * @return string|null The value of the selected option. */ public function get_selected_value(): ?string { - if (empty($this->selected) && !$this->allowempty && !empty($this->options)) { + if (is_null($this->selected) && !$this->allowempty && !empty($this->options)) { return array_key_first($this->options); } return $this->selected; @@ -244,7 +244,7 @@ class choicelist implements named_templatable, renderable { * @return string */ public function get_selected_content(renderer_base $output): string { - if (empty($this->selected)) { + if (is_null($this->selected)) { return ''; } $option = $this->options[$this->selected];