From be134e1e656d2194ffe503c9a63424b60f728dde Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Mon, 20 Jun 2022 15:57:40 -0400 Subject: [PATCH] Fix issue in InputfieldSelect.module where optionLabel() method didn't return labels for option values within optgroups --- .../modules/Inputfield/InputfieldSelect.module | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldSelect.module b/wire/modules/Inputfield/InputfieldSelect.module index 25190e2e..8c7ea26a 100644 --- a/wire/modules/Inputfield/InputfieldSelect.module +++ b/wire/modules/Inputfield/InputfieldSelect.module @@ -144,9 +144,21 @@ class InputfieldSelect extends Inputfield implements InputfieldHasSelectableOpti * */ public function optionLabel($key, $label = null) { - if(!isset($this->options[$key])) return false; - if($label !== null) $this->options[$key] = $label; - return isset($this->options[$key]) ? $this->options[$key] : null; + $returnLabel = false; + if(isset($this->options[$key])) { + if($label !== null) $this->options[$key] = $label; + $returnLabel = $this->options[$key]; + } else { + foreach($this->options as $k => $v) { + if(is_array($v) && isset($v[$key])) { + // optgroup + if($label !== null) $this->options[$k][$key] = $label; + $returnLabel = $v[$key]; + break; + } + } + } + return $returnLabel; } /**