1 | <?php |
||
9 | class SelectBox extends Field |
||
10 | { |
||
11 | |||
12 | const SELECT2_OPTION_MULTIPLE = "multiple"; |
||
13 | const SELECT2_OPTION_PLACEHOLDER = "placeholder"; |
||
14 | const SELECT2_OPTION_ALLOW_CLEAR = "allowClear"; |
||
15 | const SELECT2_OPTION_MINIMUM_RESULTS_FOR_SEARCH = "minimumResultsForSearch"; |
||
16 | |||
17 | protected $options; |
||
18 | |||
19 | /** |
||
20 | * The value to return if the "empty" option is selected |
||
21 | * @var string|null |
||
22 | */ |
||
23 | private $emptyValue; |
||
24 | |||
25 | /** |
||
26 | * Array of options passed to the select2 constructor as a javascript object |
||
27 | * @var array |
||
28 | */ |
||
29 | private $select2options; |
||
30 | |||
31 | /** |
||
32 | * @var boolean |
||
33 | */ |
||
34 | private $usePlaceholder; |
||
35 | |||
36 | /** |
||
37 | * @var boolean |
||
38 | */ |
||
39 | private $isMultipleAllowed; |
||
40 | |||
41 | /** |
||
42 | * Constructs a new SelectBox |
||
43 | * |
||
44 | * @param string $slug The field identifier |
||
45 | * @param string $label The label to display |
||
46 | * @param array $options The available options for the field |
||
47 | * @param string|string[] $value The current value or values |
||
48 | * @param bool $isMultipleAllowed Whether multiple fields can be selected |
||
49 | * @param string|string[]|bool|null $emptyValue The value to return when an empty option is selected (this |
||
50 | * is useful for relational fields in the database where you |
||
51 | * should provide NULL ). Set to FALSE if you wish to use the |
||
52 | * default empty value |
||
53 | * @param int $storeValueLocally |
||
54 | */ |
||
55 | public function __construct ($slug, $label, array $options = array(), $value = '', $isMultipleAllowed = false, $emptyValue = false, $storeValueLocally = 0) |
||
64 | |||
65 | public function getClasses () |
||
73 | |||
74 | public function getAttributes () |
||
81 | |||
82 | public function getHTML ($showLabel = true) |
||
95 | |||
96 | public function getValue ($condense = true) |
||
102 | |||
103 | public function getJsonData () |
||
109 | |||
110 | /** |
||
111 | * Merges the options |
||
112 | * |
||
113 | * @param array $select2options |
||
114 | * |
||
115 | * @return $this |
||
116 | */ |
||
117 | private function setSelect2Options ($select2options) |
||
123 | |||
124 | /** |
||
125 | * Determines the placeholder behaviour. Set to FALSE if the first option should be selected on default. Set to |
||
126 | * NULL if the label should be used. Otherwise specify a placeholder. |
||
127 | * |
||
128 | * @param null|boolean|string $placeholder |
||
129 | * |
||
130 | * @return $this |
||
131 | */ |
||
132 | public function setPlaceholder ($placeholder = null) |
||
144 | |||
145 | /** |
||
146 | * Determines the selection behaviour. If enabled, the user will be allowed to select more than one option. |
||
147 | * |
||
148 | * @param bool $multiple |
||
149 | * |
||
150 | * @return $this |
||
151 | */ |
||
152 | public function setMultipleAllowed ($multiple = true) |
||
157 | |||
158 | public function isMultiple () |
||
162 | |||
163 | /** |
||
164 | * Whether to allow the user to clear the value once it has been selected |
||
165 | * |
||
166 | * @param $allowClear |
||
167 | * |
||
168 | * @return $this |
||
169 | */ |
||
170 | public function allowClear ($allowClear) |
||
177 | |||
178 | /** |
||
179 | * If set, the search box is only displayed if the amount of results in the select box is above $minimum |
||
180 | * |
||
181 | * @param int $minimum |
||
182 | * |
||
183 | * @return $this |
||
184 | */ |
||
185 | public function setMinimumResultsForSearchBox ($minimum) |
||
192 | |||
193 | /** |
||
194 | * Determines whether the given value is currently selected |
||
195 | * |
||
196 | * @param $v |
||
197 | * |
||
198 | * @return bool |
||
199 | */ |
||
200 | protected function isSelected ($v) |
||
204 | |||
205 | protected function getRestoreDefault () |
||
210 | } |