3 # FILE: HtmlOptionList.php
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2014 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
15 # ---- PUBLIC INTERFACE --------------------------------------------------
25 function __construct($ResultVar, $Options, $SelectedValue = NULL)
27 $this->ResultVar = $ResultVar;
28 $this->Options = $Options;
46 # start out with empty HTML
49 # if there are options or we are supposed to print even if no options
52 # begin select element
53 $Html .=
'<select name="'.$this->ResultVar.
'"'
54 .
' size="'.$this->
Size.
'"'
55 .
' id="'.$this->ResultVar.
'"';
59 { $Html .=
' onChange="'.$this->OnChangeAction.
'"'; }
61 { $Html .=
' onChange="submit()"'; }
67 foreach ($this->Options as $Value => $Label)
69 # start option element
70 $Html .=
' <option value="'.htmlspecialchars($Value).
'"';
72 # add in selected attribute if appropriate
80 # add in disabled attribute if appropriate
86 # add label and end option element
87 $Html .=
">".htmlspecialchars($Label).
"</option>\n";
94 # return generated HTML to caller
108 if ($Options !== NULL)
110 if (is_array($Options))
119 return $this->DisabledOptions;
130 if ($NewValue !== NULL)
134 return $this->SelectedValue;
142 function Size($NewValue = NULL)
144 if ($NewValue !== NULL)
146 $this->
Size = intval($NewValue);
159 if ($NewValue !== NULL)
163 return $this->MultipleAllowed;
176 if ($NewValue !== NULL)
180 return $this->SubmitOnChange;
196 if ($NewValue !== NULL)
200 return $this->OnChangeAction;
214 if ($NewValue !== NULL)
218 return $this->PrintIfEmpty;
222 # ---- PRIVATE INTERFACE -------------------------------------------------
227 private $DisabledOptions = array();
228 private $MultipleAllowed = FALSE;
229 private $OnChangeAction =
"submit()";
230 private $PrintIfEmpty = TRUE;
231 private $SelectedValue;
233 private $SubmitOnChange = FALSE;
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.
GetHtml()
Get HTML for list.
PrintHtml()
Print HTML for list.
MultipleAllowed($NewValue=NULL)
Get/set whether multiple items may be selected.
Size($NewValue=NULL)
Get/set the list size (number of visible items).
OnChangeAction($NewValue=NULL)
Get/set action to take if form is submitted on change.
SelectedValue($NewValue=NULL)
Get/set currently selected value or array of currently selected values.
Convenience class for generating an HTML select/option form element.
DisabledOptions($Options=NULL)
Get/set disabled options.