From 3e54b25a91745b44142984bb8e9dafdcac63aeb2 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 20 Dec 2022 15:45:50 -0700 Subject: [PATCH] Fix for option group validation --- api/src/Etemplate/Widget/Select.php | 8 +++++++- preferences/inc/class.preferences_hooks.inc.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/api/src/Etemplate/Widget/Select.php b/api/src/Etemplate/Widget/Select.php index 9f11df835c..728b749238 100644 --- a/api/src/Etemplate/Widget/Select.php +++ b/api/src/Etemplate/Widget/Select.php @@ -169,7 +169,13 @@ class Select extends Etemplate\Widget { if ($child->type == 'option') $allowed[] = (string)$child->attrs['value']; } - $allowed = array_map('strval', $allowed); + // Make sure values are strings so they match, also handling option groups + $stringified = array(); + array_walk_recursive($allowed, function ($a, $b) use (&$stringified) { + if($b == 'value') $stringified[] = $a; + else if (is_int($b)) $stringified[] = strval($a); + }); + $allowed = $stringified; // Add empty as an option, we check for required value later $allowed[] = ''; diff --git a/preferences/inc/class.preferences_hooks.inc.php b/preferences/inc/class.preferences_hooks.inc.php index 8649b26f46..237cafab5c 100644 --- a/preferences/inc/class.preferences_hooks.inc.php +++ b/preferences/inc/class.preferences_hooks.inc.php @@ -363,7 +363,7 @@ class preferences_hooks 'type' => 'multiselect', 'label' => 'Permanent time zone selection', 'name' => 'tz_selection', - 'values' => $tzs ? array_merge(...array_values($tzs)) : null, // only flat arrays supported + 'values' => $tzs 'help' => 'Please select timezones, you want to be able to quickly switch between. Switch is NOT shown, if less then two are selected.', 'xmlrpc' => True, 'admin' => False,