Skip to content

Commit

Permalink
Merge pull request #5545 from BOINC/dpa_form_select
Browse files Browse the repository at this point in the history
form_select_multiple(): optional arg is list of selected values
  • Loading branch information
AenBleidd authored Mar 21, 2024
2 parents 87dc71e + 9653f4a commit f5c35e5
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions html/inc/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ function form_input_textarea($label, $name, $value='', $nrows=4) {

// $items is either a string of <option> elements, or an array
//
function form_select($label, $name, $items) {
function form_select($label, $name, $items, $selected=null) {
echo sprintf('
<div class="form-group">
<label align=right class="%s" for="%s">%s</label>
Expand All @@ -377,8 +377,11 @@ function form_select($label, $name, $items) {
);
if (is_array($items)) {
foreach ($items as $i) {
echo '<option value="'.$i[0].'">'.$i[1].'</option>
';
echo sprintf(
'<option %s value=%s>%s</option>',
($i[0]==$selected)?'selected':'',
$i[0], $i[1]
);
}
} else {
echo $items;
Expand All @@ -387,9 +390,9 @@ function form_select($label, $name, $items) {
}

// same, for multiple select.
// flags, if non-null, says which ones are selected
// $selected, if non-null, is a list of selected values
//
function form_select_multiple($label, $name, $items, $flags=null) {
function form_select_multiple($label, $name, $items, $selected=null) {
echo sprintf('
<div class="form-group">
<label align=right class="%s" for="%s">%s</label>
Expand All @@ -398,12 +401,12 @@ function form_select_multiple($label, $name, $items, $flags=null) {
',
FORM_LEFT_CLASS, $name, $label, FORM_RIGHT_CLASS, $name, $name
);
$n = 0;
foreach ($items as $i) {
$s = ($flags && $flags[$n])?'selected':'';
echo '<option '.$s.' value="'.$i[0].'">'.$i[1].'</option>
';
$n++;
echo sprintf(
'<option %s value=%s>%s</option>',
($selected && in_array($i[0], $selected))?'selected':'',
$i[0], $i[1]
);
}
echo "</select></div></div>\n";
}
Expand Down

0 comments on commit f5c35e5

Please sign in to comment.