PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.1.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.1.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 / SliderField.php

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

114 lines 4.2 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 use BitCode\BitForm\Core\Util\FrontendHelpers;
6
7 class SliderField
8 {
9 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
10 {
11 $inputWrapper = new ClassicInputWrapper($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error, $value);
12 $input = self::field($field, $rowID, $form_atomic_Cls_map, $value);
13 return $inputWrapper->wrapper($input);
14 }
15
16 private static function field($field, $rowID, $form_atomic_Cls_map, $value)
17 {
18 $fieldHelpers = new ClassicFieldHelpers($field, $rowID, $form_atomic_Cls_map);
19
20 $prefixIcn = $fieldHelpers->icon('prefixIcn', 'pre-i');
21 $suffixIcn = $fieldHelpers->icon('suffixIcn', 'suf-i');
22 $sugg = '';
23 $req = $fieldHelpers->required();
24 $disabled = $fieldHelpers->disabled();
25 $readonly = $fieldHelpers->readonly();
26 $inputMode = '';
27 $name = $fieldHelpers->name();
28 $ac = $fieldHelpers->autocomplete();
29 $mx = '';
30 $mn = '';
31 $step = '';
32 $ph = $fieldHelpers->placeholder();
33 $value = $fieldHelpers->value();
34 $ariaDescribedBy = $fieldHelpers->ariaDescribedBy();
35 $ariaRequired = $fieldHelpers->ariaRequired();
36 $list = '';
37 $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds;
38 $contentCount = count($bfFrontendFormIds);
39
40 if (property_exists($field, 'suggestions') && count($field->suggestions) > 0) {
41 $list = "list='{$rowID}-{$contentCount}-datalist'";
42 $sugg .= "<datalist id='{$rowID}-{$contentCount}-datalist'>";
43 foreach ($field->suggestions as $suggestion) {
44 $val = (isset($suggestion->val) && !empty($suggestion->val)) ? $suggestion->val : $suggestion->lbl;
45 $sugg .= "<option value='{$fieldHelpers->esc_attr($val)}'>{$fieldHelpers->esc_html($suggestion->lbl)}</option>";
46 }
47 $sugg .= '</datalist>';
48 }
49
50 if (property_exists($field, 'mn') && '' !== $field->mn) {
51 $mn = "min='{$fieldHelpers->esc_attr($field->mn)}'";
52 }
53
54 if (property_exists($field, 'mx') && '' !== $field->mx) {
55 $mx = "max='{$fieldHelpers->esc_attr($field->mx)}'";
56 }
57
58 if (property_exists($field, 'step') && '' !== $field->step) {
59 $step = "step='{$fieldHelpers->esc_attr($field->step)}'";
60 }
61
62 if (property_exists($field, 'inputMode') && '' !== $field->inputMode) {
63 $inputMode = "inputMode='{$fieldHelpers->esc_attr($field->inputMode)}'";
64 }
65
66 $minValue = property_exists($field, 'mn') ? $field->mn : 0;
67 $maxValue = property_exists($field, 'mx') ? $field->mx : 100;
68
69 $defaultVal = (($maxValue - $minValue) / 2) + $minValue;
70 if ($fieldHelpers->property_exists_nested($field, 'val', '', 1)) {
71 $defaultVal = $field->val;
72 } elseif ($fieldHelpers->property_exists_nested($field, 'defaultValue', '', 1)) {
73 $defaultVal = $field->defaultValue;
74 }
75
76 $lowerTrackPercentage = ($defaultVal - $minValue) / ($maxValue - $minValue) * 100;
77
78 $wrpperStyle = "style='--bfv-fld-val: \"" . $fieldHelpers->esc_attr($defaultVal) . "\";'";
79 $inputStyle = "style='--bfv-fill-lower-track: " . $fieldHelpers->esc_attr($lowerTrackPercentage) . "% !important;'";
80
81 return ' <div
82 ' . $fieldHelpers->getCustomAttributes('inp-fld-wrp') . '
83 class="' . $fieldHelpers->getAtomicCls('inp-fld-wrp') . ' ' . $fieldHelpers->getCustomClasses('inp-fld-wrp') . '"
84 ' . $wrpperStyle . '
85 >
86 <input
87 ' . $fieldHelpers->getCustomAttributes('fld') . '
88 id="' . $rowID . '-' . $contentCount . '"
89 ' . $list . '
90 class="' . $fieldHelpers->getAtomicCls('fld') . ' ' . $fieldHelpers->getCustomClasses('fld') . '"
91 type="' . $fieldHelpers->esc_attr($field->typ) . '"
92 ' . $req . '
93 ' . $ariaRequired . '
94 ' . $ariaDescribedBy . '
95 ' . $disabled . '
96 ' . $readonly . '
97 ' . $ph . '
98 ' . $mn . '
99 ' . $mx . '
100 ' . $step . '
101 ' . $ac . '
102 ' . $inputMode . '
103 ' . $name . '
104 ' . $value . '
105 ' . $inputStyle . '
106 />
107 ' . $prefixIcn . '
108 ' . $suffixIcn . '
109 <span class="' . $fieldHelpers->getAtomicCls('slider-val') . '">Value : </span>
110 </div>
111 ' . $sugg . "\n";
112 }
113 }
114