1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-11 01:04:16 +02:00

Fix issue in InputfieldSelect.module where optionLabel() method didn't return labels for option values within optgroups

This commit is contained in:
Ryan Cramer
2022-06-20 15:57:40 -04:00
parent 773a344a2f
commit be134e1e65

View File

@@ -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;
}
/**