3 # FILE: HtmlOptionList.php 5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2014-2015 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 16 # ---- PUBLIC INTERFACE -------------------------------------------------- 26 public function __construct($ResultVar, $Options, $SelectedValue = NULL)
28 $this->ResultVar = $ResultVar;
29 $this->Options = $Options;
47 # start out with empty HTML 50 # if there are options or we are supposed to print even if no options 53 # begin select element 54 $Html .=
'<select name="'.$this->ResultVar.
'"' 55 .
' size="'.$this->
Size.
'"' 56 .
' id="'.$this->ResultVar.
'"';
60 { $Html .=
' onChange="'.$this->OnChangeAction.
'"'; }
62 { $Html .=
' onChange="submit()"'; }
65 if ($this->
Disabled) { $Html .=
' disabled'; }
69 foreach ($this->Options as $Value => $Label)
71 # start option element 72 $Html .=
' <option value="'.htmlspecialchars($Value).
'"';
74 # add in selected attribute if appropriate 82 # add in disabled attribute if appropriate 88 # add label and end option element 89 $Html .=
">".htmlspecialchars($Label).
"</option>\n";
96 # return generated HTML to caller 110 if ($Options !== NULL)
112 if (is_array($Options))
121 return $this->DisabledOptions;
132 if ($NewValue !== NULL)
136 return $this->SelectedValue;
144 public function Size($NewValue = NULL)
146 if ($NewValue !== NULL)
148 $this->
Size = intval($NewValue);
161 if ($NewValue !== NULL)
165 # adjust form field name (result variable) if needed 167 && (substr($this->ResultVar, -2) !=
"[]"))
169 $this->ResultVar .=
"[]";
172 && (substr($this->ResultVar, -2) ==
"[]"))
174 $this->ResultVar .= substr($this->ResultVar, 0, -2);
177 return $this->MultipleAllowed;
190 if ($NewValue !== NULL)
194 return $this->SubmitOnChange;
210 if ($NewValue !== NULL)
214 return $this->OnChangeAction;
228 if ($NewValue !== NULL)
232 return $this->PrintIfEmpty;
244 if ($NewValue !== NULL)
246 $this->
Disabled = $NewValue ? TRUE : FALSE;
248 return $this->Disabled;
252 # ---- PRIVATE INTERFACE ------------------------------------------------- 257 private $Disabled = FALSE;
258 private $DisabledOptions = array();
259 private $MultipleAllowed = FALSE;
260 private $OnChangeAction =
"submit()";
261 private $PrintIfEmpty = TRUE;
262 private $SelectedValue;
264 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.
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.
Convenience class for generating an HTML select/option form element.
DisabledOptions($Options=NULL)
Get/set disabled options.