From 2a003a903c728db071cfe16e3e16d8495f8d8470 Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 26 Oct 2004 07:42:08 +0000 Subject: [PATCH] Changes in the way optgroups are handled for XHTML compatibility --- lib/weblib.php | 51 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index 961f1d10ae..441774f19b 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -588,7 +588,7 @@ function close_window_button() { echo '-->' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } @@ -694,29 +694,52 @@ function popup_form($common, $options, $formname, $selected='', $nothing='choose $inoptgroup = false; foreach ($options as $value => $label) { - if (substr($label,0,2) == '--') { - if ($inoptgroup) { + + if (substr($label,0,2) == '--') { /// we are starting a new optgroup + + /// Check to see if we already have a valid open optgroup + /// XHTML demands that there be at least 1 option within an optgroup + if ($inoptgroup and (count($optgr) > 1) ) { + $output .= implode('', $optgr); $output .= ' '; - } else { - $inoptgroup = true; } - $output .= ' '; // Plain labels + + unset($optgr); + $optgr = array(); + + $optgr[] = ' '; // Plain labels + + $inoptgroup = true; /// everything following will be in an optgroup continue; + } else { - $output .= ' ' . "\n"; + } + + if ($inoptgroup) { + $optgr[] = $optstr; + } else { + $output .= $optstr; } } - if ($label) { - $output .= '>'. $label .'' . "\n"; - } else { - $output .= '>'. $value .'' . "\n"; - } + } - if ($inoptgroup) { + + /// catch the final group if not closed + if ($inoptgroup and count($optgr) > 1) { + $output .= implode('', $optgr); $output .= ' '; } + $output .= ''; $output .= ''; -- 2.39.5