2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 import('form.FormElement');
31 // name CDATA #IMPLIED -- field name --
32 // size NUMBER #IMPLIED -- rows visible --
33 // multiple (multiple) #IMPLIED -- default is single selection --
34 // disabled (disabled) #IMPLIED -- unavailable in this context --
35 // tabindex NUMBER #IMPLIED -- position in tabbing order --
36 // onfocus %Script; #IMPLIED -- the element got the focus --
37 // onblur %Script; #IMPLIED -- the element lost the focus --
38 // onchange %Script; #IMPLIED -- the element value was changed --
40 class Combobox extends FormElement {
41 var $mMultiple = false;
42 var $mOptions = array();
43 var $mOptionsEmpty = array();
44 var $mCompareOn = "key"; // or "value"
46 var $mDataKeys = array();
47 var $cClassName = "Combobox";
49 function __construct($name,$value="")
52 $this->mValue = $value;
55 function setMultiple($value) { $this->mMultiple = $value; }
56 function isMultiple() { return $this->mMultiple; }
58 function setData($value) { $this->mOptions = $value; }
59 function getData() { return $this->mOptions; }
61 function setDataDefault($value) { $this->mOptionsEmpty = $value; }
62 function getDataDefault() { return $this->mOptionsEmpty; }
64 function setDataKeys($keys) { $this->mDataKeys = $keys; $this->mDataDeep = 2; }
65 function getDataKeys() { return $this->mDataKeys; }
68 function toStringControl() {
69 if (!$this->isRenderable()) return "";
71 if ($this->mId=="") $this->mId = $this->mName;
73 $html = "\n\t<select";
74 $html .= " name=\"$this->mName\" id=\"$this->mId\"";
77 $html .= " size=\"$this->mSize\"";
82 if ($this->mTabindex!="")
83 $html .= " tabindex=\"$this->mTabindex\"";
85 if ($this->mOnChange!="")
86 $html .= " onchange=\"$this->mOnChange\"";
88 if ($this->mStyle!="")
89 $html .= " style=\"$this->mStyle\"";
91 if (!$this->isEnable())
95 if (is_array($this->mOptionsEmpty) && (count($this->mOptionsEmpty) > 0))
96 foreach ($this->mOptionsEmpty as $key=>$value) {
97 $html .= "<option value=\"".$key."\"";
98 if (($this->mValue == $value) && ($this->mValue != '')) $html .= " selected";
99 $html .= ">".$value."</option>\n";
101 if (is_array($this->mOptions) && (count($this->mOptions) > 0))
102 foreach ($this->mOptions as $key=>$value) {
104 if ($this->mDataDeep>1) {
105 $key = $value[$this->mDataKeys[0]];
106 $value = $value[$this->mDataKeys[1]];
108 $html .= "<option value=\"".$key."\"";
109 if (($this->mValue == $key) && ($this->mValue != '')) $html .= " selected";
110 $html .= ">".htmlspecialchars($value)."</option>\n";
113 $html .= "</select>";