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 59 foreach ($this->Options as $Value => $Label)
61 # if option is actually a group of options 65 $Html .=
" <optgroup label=\"" 66 .htmlspecialchars($Value).
"\">\n";
68 # for each option in group 69 foreach ($Label as $GValue => $GLabel)
76 $Html .=
" </optgroup>\n";
88 # return generated HTML to caller 124 if ($NewValue !== NULL)
136 public function Size($NewValue = NULL)
138 if ($NewValue !== NULL)
140 $this->
Size = intval($NewValue);
153 if ($NewValue !== NULL)
157 # adjust form field name (result variable) if needed 159 && (substr($this->ResultVar, -2) !=
"[]"))
161 $this->ResultVar .=
"[]";
164 && (substr($this->ResultVar, -2) ==
"[]"))
166 $this->ResultVar .= substr($this->ResultVar, 0, -2);
182 if ($NewValue !== NULL)
202 if ($NewValue !== NULL)
220 if ($NewValue !== NULL)
236 if ($NewValue !== NULL)
238 $this->
Disabled = $NewValue ? TRUE : FALSE;
250 if ($NewValue !== NULL)
252 $this->ListClasses = $NewValue;
270 if ($NewValue !== NULL)
272 $this->OptionClasses = $NewValue;
287 if ($NewValue !== NULL)
289 $this->OptionData = $NewValue;
304 if ($NewValue !== NULL)
320 $this->AdditionalAttributes[$Name] = $Value;
324 # ---- PRIVATE INTERFACE ------------------------------------------------- 349 # start option element 350 $Html =
' <option value="'.htmlspecialchars($Value).
'"';
352 # add in selected attribute if appropriate 357 $Html .=
' selected';
360 # add in disabled attribute if appropriate 363 $Html .=
' disabled';
366 # add in class if requested 367 if ($this->OptionClasses)
369 if (is_array($this->OptionClasses))
371 if (isset($this->OptionClasses[$Value]))
374 .htmlspecialchars($this->OptionClasses[$Value]).
'"';
380 .htmlspecialchars($this->OptionClasses).
'"';
384 # add in data attributes if requested 385 if (isset($this->OptionData[$Value]))
387 foreach ($this->OptionData[$Value] as $DName => $DVal)
389 $DName = preg_replace(
'/[^a-z0-9-]/',
'', strtolower($DName));
390 $Html .=
' data-'.$DName.
'="'.htmlspecialchars($DVal).
'"';
394 # substring label to its max length if requested 400 # add label and end option element 401 $Html .=
">".htmlspecialchars($Label).
"</option>\n";
412 $Html =
'<select name="'.$this->ResultVar.
'"' 413 .
' size="'.$this->
Size.
'"' 414 .
' id="'.$this->ResultVar.
'"';
416 if ($this->ListClasses)
418 $Html .=
' class="'.htmlspecialchars($this->ListClasses).
'"';
424 { $Html .=
' onChange="'.$this->OnChangeAction.
'"'; }
426 { $Html .=
' onChange="submit()"'; }
431 if ($this->
Disabled) { $Html .=
' disabled'; }
433 foreach ($this->AdditionalAttributes as $Name => $Value)
435 $Html .=
" ".$Name.
"=\"".htmlspecialchars($Value).
"\"";
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.
GetSelectOpenTag()
Get HTML for tag to begin list.
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.
AddAttribute($Name, $Value)
Add an attribute for the <select> tag for the list.
MaxLabelLength($NewValue=NULL)
Get/set the maximum number of character a label will be displayed.
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.