3 # FILE: HtmlOptionList.php 5 # Part of the ScoutLib application support library 6 # Copyright 2014-2017 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu 16 # ---- PUBLIC INTERFACE -------------------------------------------------- 49 # start out with empty HTML 52 # if there are options or we are supposed to print even if no options 55 # begin select element 56 $Html .=
'<select name="'.$this->ResultVar.
'"' 57 .
' size="'.$this->
Size.
'"' 58 .
' id="'.$this->ResultVar.
'"';
59 if ($this->ListClasses)
61 $Html .=
' class="'.htmlspecialchars($this->ListClasses).
'"';
66 { $Html .=
' onChange="'.$this->OnChangeAction.
'"'; }
68 { $Html .=
' onChange="submit()"'; }
71 if ($this->
Disabled) { $Html .=
' disabled'; }
75 foreach ($this->Options as $Value => $Label)
77 # if option is actually a group of options 81 $Html .=
" <optgroup label=\"" 82 .htmlspecialchars($Value).
"\">\n";
84 # for each option in group 85 foreach ($Label as $GValue => $GLabel)
92 $Html .=
" </optgroup>\n";
101 $Html .=
'</select>';
104 # return generated HTML to caller 140 if ($NewValue !== NULL)
152 public function Size($NewValue = NULL)
154 if ($NewValue !== NULL)
156 $this->
Size = intval($NewValue);
169 if ($NewValue !== NULL)
173 # adjust form field name (result variable) if needed 175 && (substr($this->ResultVar, -2) !=
"[]"))
177 $this->ResultVar .=
"[]";
180 && (substr($this->ResultVar, -2) ==
"[]"))
182 $this->ResultVar .= substr($this->ResultVar, 0, -2);
198 if ($NewValue !== NULL)
218 if ($NewValue !== NULL)
236 if ($NewValue !== NULL)
252 if ($NewValue !== NULL)
254 $this->
Disabled = $NewValue ? TRUE : FALSE;
266 if ($NewValue !== NULL)
268 $this->ListClasses = $NewValue;
286 if ($NewValue !== NULL)
288 $this->OptionClasses = $NewValue;
303 if ($NewValue !== NULL)
305 $this->OptionData = $NewValue;
310 # ---- PRIVATE INTERFACE ------------------------------------------------- 334 # start option element 335 $Html =
' <option value="'.htmlspecialchars($Value).
'"';
337 # add in selected attribute if appropriate 342 $Html .=
' selected';
345 # add in disabled attribute if appropriate 348 $Html .=
' disabled';
351 # add in class if requested 352 if ($this->OptionClasses)
354 if (is_array($this->OptionClasses))
356 if (isset($this->OptionClasses[$Value]))
359 .htmlspecialchars($this->OptionClasses[$Value]).
'"';
365 .htmlspecialchars($this->OptionClasses).
'"';
369 # add in data attributes if requested 370 if (isset($this->OptionData[$Value]))
372 foreach ($this->OptionData[$Value] as $DName => $DVal)
374 $DName = preg_replace(
'/[^a-z0-9-]/',
'', strtolower($DName));
375 $Html .=
' data-'.$DName.
'="'.htmlspecialchars($DVal).
'"';
379 # add label and end option element 380 $Html .=
">".htmlspecialchars($Label).
"</option>\n";
SubmitOnChange($NewValue=NULL)
Get/set whether to submit the form when the list value is changed.
PrintIfEmpty($NewValue=NULL)
Get/set whether list should be output even if there are no items.
__construct($ResultVar, $Options, $SelectedValue=NULL)
Class constructor.
ClassForOptions($NewValue=NULL)
Get/set CSS class(es) for the options.
GetHtml()
Get HTML for list.
PrintHtml()
Print HTML for list.
MultipleAllowed($NewValue=NULL)
Get/set whether multiple items may be selected.
DataForOptions($NewValue=NULL)
Get/set HTML data attributes for the options.
Size($NewValue=NULL)
Get/set the list size (number of visible items).
GetOptionTag($Value, $Label)
Get HTML for one option.
OnChangeAction($NewValue=NULL)
Get/set action to take if form is submitted on change.
Disabled($NewValue=NULL)
Get/set whether the whole option list is editable.
SelectedValue($NewValue=NULL)
Get/set currently selected value or array of currently selected values.
ClassForList($NewValue=NULL)
Get/set CSS class(es) for the list.
Convenience class for generating an HTML select/option form element.
DisabledOptions($Options=NULL)
Get/set disabled options.