PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / -3.0.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v-3.0.1
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
bit-form / includes / Frontend / Form / View / Theme / Fields / DropdownField.php

DropdownField.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder -3.0.1, at includes/Frontend/Form/View/Theme/Fields/DropdownField.php

463 lines 16.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields;
4
5 class DropdownField
6 {
7 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
8 {
9 $inputWrapper = new ClassicInputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
10 $input = self::field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
11 return $inputWrapper->wrapper($input);
12 }
13
14 private static function field($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
15 {
16 $fh = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map);
17 $ph = isset($field->ph) ? $field->ph : '';
18 $val = !empty($value) ? $value : $fh->value();
19 $val = 'array' === gettype($val) ? ("value='" . implode(',', $val) . "'") : $val;
20 $name = $fh->name();
21 $req = $fh->required();
22 $readonlyCls = isset($field->valid->readonly) ? 'readonly' : '';
23 $disabledCls = isset($field->valid->disabled) ? 'disabled' : '';
24 $selectedOptImage = '';
25 $optionsList = '';
26 $activeList = isset($field->config->activeList) ? $field->config->activeList : null;
27 $allowCustomOption = apply_filters('bitform_dropdown_allow_custom_option', false, $field);
28 $img = htmlentities("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'/>");
29
30 $selectedOptImage = apply_filters('bitform_dropdown_selected_opt_image', '', $field, $fh);
31
32 if (property_exists($field, 'optionsList')) {
33 foreach ($field->optionsList as $key => $value) {
34 $dataIndex = 0;
35 $valueArr = (array) $value;
36 $listName = array_keys($valueArr)[0];
37 $options = array_values($valueArr)[0];
38
39 $optionsList .= sprintf(
40 '<ul
41 %1$s
42 class="%2$s %3$s"
43 aria-hidden="true"
44 aria-label="Option List"
45 data-list="%4$s"
46 data-list-index="%5$s"
47 tabIndex="-1"
48 role="listbox"
49 >',
50 $fh->getCustomAttributes('option-list'),
51 $fh->getAtomicCls('option-list'),
52 $fh->getCustomClasses('option-list'),
53 $fh->esc_attr($listName),
54 $key
55 );
56 if ($allowCustomOption) {
57 $optionsList .= sprintf(
58 '<li
59 %1$s
60 data-index=%2$s
61 data-value="create-opt"
62 class="option create-opt %3$s"
63 role="option"
64 aria-selected="false"
65 tabIndex="-1"
66 style="display: none !important;"
67 >
68 <span
69 %4$s
70 class="opt-lbl-wrp %5$s"
71 >
72 <span
73 %6$s
74 class="opt-lbl %7$s"
75 >
76 Create:
77 </span>
78 </span>
79 <span class="opt-prefix"></span>
80 </li>',
81 $fh->getCustomAttributes('option'),
82 $dataIndex,
83 $fh->getCustomClasses('option'),
84 $fh->getCustomAttributes('opt-lbl-wrp'),
85 $fh->getCustomClasses('opt-lbl-wrp'),
86 $fh->getCustomAttributes('opt-lbl'),
87 $fh->getCustomClasses('opt-lbl')
88 );
89 }
90
91 foreach ($options as $opt) {
92 if (isset($opt->type)) {
93 $disableOpt = isset($opt->disabled) ? 'disabled-opt' : '';
94 $optionsList .= sprintf(
95 '<li
96 data-index=%1$s
97 %2$s
98 class="option opt-group-title %3$s %4$s"
99 >
100 <span
101 %5$s
102 class="opt-lbl %6$s"
103 >
104 %7$s
105 </span>
106 </li>',
107 $dataIndex,
108 $fh->getCustomAttributes('option'),
109 $fh->getCustomClasses('option'),
110 $disableOpt,
111 $fh->getCustomAttributes('opt-lbl'),
112 $fh->getCustomClasses('opt-lbl'),
113 $fh->kses_post($opt->title)
114 );
115 foreach ($opt->childs as $child) {
116 $optVal = isset($child->val) ? $child->val : $child->lbl;
117 $disableOpt = (isset($opt->disabled) || isset($child->disabled)) ? 'disabled-opt' : '';
118 $optImage = '';
119 if (isset($child->img)) {
120 $optImage = sprintf(
121 '<img
122 %1$s
123 class="opt-icn %2$s"
124 aria-hidden="true"
125 alt="%3$s"
126 src="%4$s"
127 >',
128 $fh->getCustomAttributes('opt-icn'),
129 $fh->getCustomClasses('opt-icn'),
130 $fh->esc_attr($child->lbl),
131 $fh->esc_url($child->img)
132 );
133 }
134 $optionsList .= sprintf(
135 '<li
136 %1$s
137 data-index="%2$s"
138 data-value="%3$s"
139 class="option opt-group-child %4$s %5$s"
140 role="option"
141 aria-selected="false"
142 tabIndex="-1"
143 >
144 <span
145 %6$s
146 class="opt-lbl-wrp %7$s"
147 >
148 %8$s
149 <span
150 %9$s
151 class="opt-lbl %10$s"
152 >
153 %11$s
154 </span>
155 </span>
156 <span class="opt-prefix" />
157 </li>',
158 $fh->getCustomAttributes('option'),
159 $dataIndex,
160 $fh->esc_attr($optVal),
161 $fh->getCustomClasses('option'),
162 $disableOpt,
163 $fh->getCustomAttributes('opt-lbl-wrp'),
164 $fh->getCustomClasses('opt-lbl-wrp'),
165 $optImage,
166 $fh->getCustomAttributes('opt-lbl'),
167 $fh->getCustomClasses('opt-lbl'),
168 $fh->kses_post($child->lbl)
169 );
170 }
171 } else {
172 $optVal = isset($opt->val) ? $opt->val : $opt->lbl;
173 $disableOpt = isset($opt->disabled) ? 'disabled-opt' : '';
174 $optImage = '';
175 if (isset($opt->img)) {
176 $optImage = sprintf(
177 '<img
178 %1$s
179 class="opt-icn %2$s"
180 aria-hidden="true"
181 alt="%3$s"
182 src="%4$s"
183 >',
184 $fh->getCustomAttributes('opt-icn'),
185 $fh->getCustomClasses('opt-icn'),
186 $fh->esc_attr($opt->lbl),
187 $fh->esc_url($opt->img)
188 );
189 }
190 $optionsList .= sprintf(
191 '<li
192 %1$s
193 data-index="%2$s"
194 data-value="%3$s"
195 class="option %4$s %5$s"
196 role="option"
197 aria-selected="false"
198 tabIndex="-1"
199 >
200 <span
201 %6$s
202 class="opt-lbl-wrp %7$s"
203 >
204 %8$s
205 <span
206 %9$s
207 class="opt-lbl %10$s"
208 >
209 %11$s
210 </span>
211 </span>
212 <span class="opt-prefix" />
213 </li>',
214 $fh->getCustomAttributes('option'),
215 $dataIndex,
216 $fh->esc_attr($optVal),
217 $fh->getCustomClasses('option'),
218 $disableOpt,
219 $fh->getCustomAttributes('opt-lbl-wrp'),
220 $fh->getCustomClasses('opt-lbl-wrp'),
221 $optImage,
222 $fh->getCustomAttributes('opt-lbl'),
223 $fh->getCustomClasses('opt-lbl'),
224 $fh->kses_post($opt->lbl)
225 );
226 }
227 }
228 $optionsList .= '</ul>';
229 $dataIndex++;
230 }
231
232 $optionsList .= sprintf(
233 '<ul
234 %1$s
235 class="%2$s %3$s active-list"
236 aria-hidden="true"
237 aria-label="Option List"
238 tabIndex="-1"
239 role="listbox"
240 >
241 </ul>',
242 $fh->getCustomAttributes('option-list'),
243 $fh->getAtomicCls('option-list'),
244 $fh->getCustomClasses('option-list')
245 );
246
247 $multiChipClass = ($fh->property_exists_nested($field, 'config->multipleSelect', true) && $fh->property_exists_nested($field, 'config->showChip', true)) ? 'multi-chip' : '';
248
249 return sprintf(
250 '<div class="%1$s %2$s">
251 <div
252 %3$s
253 class="%4$s %5$s %6$s %7$s"
254 >
255 <input
256 %8$s
257 %9$s
258 type="text"
259 title="Dropdown Hidden Input"
260 class="%10$s d-none"
261 %11$s
262 %12$s
263 %13$s
264 />
265 <div
266 %14$s
267 class="%15$s %16$s"
268 role="combobox"
269 aria-controls=""
270 aria-haspopup="listbox"
271 aria-live="assertive"
272 aria-expanded="false"
273 tabIndex="0"
274 aria-label="Dropdown"
275 >
276 <div
277 %17$s
278 class="%18$s %19$s"
279 >
280 %20$s
281 <span
282 %21$s
283 aria-label="Selected Option Label"
284 class="%22$s %23$s %24$s"
285 >
286 %25$s
287 </span>
288 </div>
289 <div
290 %26$s
291 class="%27$s %28$s"
292 >
293 <button
294 %29$s
295 type="button"
296 aria-label="Clear selected option value"
297 class="%30$s %31$s"
298 >
299 <svg
300 width="15"
301 height="15"
302 role="img"
303 title="Cross icon"
304 viewBox="0 0 24 24"
305 fill="none"
306 stroke="currentColor"
307 stroke-width="2"
308 stroke-linecap="round"
309 stroke-linejoin="round"
310 >
311 <line x1="18" y1="6" x2="6" y2="18" />
312 <line x1="6" y1="6" x2="18" y2="18" />
313 </svg>
314 </button>
315 <div
316 %32$s
317 class="%33$s %34$s"
318 >
319 <svg
320 width="15"
321 height="15"
322 viewBox="0 0 24 24"
323 title="Down icon"
324 role="img"
325 fill="none"
326 stroke="currentColor"
327 stroke-width="2"
328 stroke-linecap="round"
329 stroke-linejoin="round"
330 >
331 <polyline points="6 9 12 15 18 9" />
332 </svg>
333 </div>
334 </div>
335 </div>
336 <div
337 %35$s
338 class="%36$s %37$s"
339 >
340 <div
341 %38$s
342 class="%39$s %40$s"
343 >
344 <div
345 %41$s
346 class="%42$s %43$s"
347 >
348 <input
349 %44$s
350 type="search"
351 class="%45$s %46$s"
352 placeholder="Search Country"
353 aria-label="Search Options"
354 aria-hidden="true"
355 tabIndex="-1"
356 inert
357 />
358 <svg
359 %47$s
360 class="%48$s %49$s %50$s"
361 aria-hidden="true"
362 width="22"
363 height="22"
364 role="img"
365 title="Search icon"
366 viewBox="0 0 24 24"
367 fill="none"
368 stroke="currentColor"
369 stroke-width="2"
370 stroke-linecap="round"
371 stroke-linejoin="round"
372 >
373 <circle cx="11" cy="11" r="8" />
374 <line x1="21" y1="21" x2="16.65" y2="16.65" />
375 </svg>
376 <button
377 %51$s
378 type="button"
379 aria-label="Clear search"
380 class="%52$s %53$s %54$s"
381 tabIndex="-1"
382 >
383 <svg
384 width="13"
385 height="13"
386 role="img"
387 viewBox="0 0 24 24"
388 fill="none"
389 stroke="currentColor"
390 stroke-width="2"
391 stroke-linecap="round"
392 stroke-linejoin="round"
393 >
394 <line x1="18" y1="6" x2="6" y2="18" />
395 <line x1="6" y1="6" x2="18" y2="18" />
396 </svg>
397 </button>
398 </div>
399 %55$s
400 </div>
401 </div>
402 </div>
403 </div>',
404 $fh->getAtomicCls('dpd-fld-container'), // 1
405 $fh->getCustomClasses('dpd-fld-container'), // 2
406 $fh->getCustomAttributes('dpd-fld-wrp'), // 3
407 $fh->getAtomicCls('dpd-fld-wrp'), // 4
408 $fh->getCustomClasses('dpd-fld-wrp'), // 5
409 $readonlyCls, // 6
410 $disabledCls, // 7
411 $name, // 8
412 $req, // 9
413 $fh->getAtomicCls('dpd-hidden-input'), // 10
414 $fh->disabled(), // 11
415 $fh->readonly(), // 12
416 $val, // 13
417 $fh->getCustomAttributes('dpd-wrp'), // 14
418 $fh->getAtomicCls('dpd-wrp'), // 15
419 $fh->getCustomClasses('dpd-wrp'), // 16
420 $fh->getCustomAttributes('selected-opt-wrp'), // 17
421 $fh->getAtomicCls('selected-opt-wrp'), // 18
422 $fh->getCustomClasses('selected-opt-wrp'), // 19
423 $selectedOptImage, // 20
424 $fh->getCustomAttributes('selected-opt-lbl'), // 21
425 $fh->getAtomicCls('selected-opt-lbl'), // 22
426 $multiChipClass, // 23
427 $fh->getCustomClasses('selected-opt-lbl'), // 24
428 $fh->esc_html($ph), // 25
429 $fh->getCustomAttributes('dpd-btn-wrp'), // 26
430 $fh->getAtomicCls('dpd-btn-wrp'), // 27
431 $fh->getCustomClasses('dpd-btn-wrp'), // 28
432 $fh->getCustomAttributes('selected-opt-clear-btn'), // 29
433 $fh->getAtomicCls('selected-opt-clear-btn'), // 30
434 $fh->getCustomClasses('selected-opt-clear-btn'), // 31
435 $fh->getCustomAttributes('dpd-down-btn'), // 32
436 $fh->getAtomicCls('dpd-down-btn'), // 33
437 $fh->getCustomClasses('dpd-down-btn'), // 34
438 $fh->getCustomAttributes('option-wrp'), // 35
439 $fh->getAtomicCls('option-wrp'), // 36
440 $fh->getCustomClasses('option-wrp'), // 37
441 $fh->getCustomAttributes('option-inner-wrp'), // 38
442 $fh->getAtomicCls('option-inner-wrp'), // 39
443 $fh->getCustomClasses('option-inner-wrp'), // 40
444 $fh->getCustomAttributes('option-search-wrp'), // 41
445 $fh->getAtomicCls('option-search-wrp'), // 42
446 $fh->getCustomClasses('option-search-wrp'), // 43
447 $fh->getCustomAttributes('opt-search-input'), // 44
448 $fh->getAtomicCls('opt-search-input'), // 45
449 $fh->getCustomClasses('opt-search-input'), // 46
450 $fh->getCustomAttributes('opt-search-icn'), // 47
451 $fh->getAtomicCls('icn'), // 48
452 $fh->getAtomicCls('opt-search-icn'), // 49
453 $fh->getCustomClasses('opt-search-icn'), // 50
454 $fh->getCustomAttributes('search-clear-btn'), // 51
455 $fh->getAtomicCls('icn'), // 52
456 $fh->getAtomicCls('search-clear-btn'), // 53
457 $fh->getCustomClasses('search-clear-btn'), // 54
458 $optionsList // 55
459 );
460 }
461 }
462 }
463