PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / V3.0.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder vV3.0.2
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 / Conversational / Fields / CountryField.php

CountryField.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder V3.0.2, at includes/Frontend/Form/View/Conversational/Fields/CountryField.php

253 lines 8.8 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\Conversational\Fields;
4
5 class CountryField
6 {
7 public static function init($field, $rowID, $field_name, $form_atomic_Cls_map, $formID, $error = null, $value = null)
8 {
9 $inputWrapper = new ConversationalInputWrapper($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 $fieldHelpers = new ConversationalFieldHelpers($formID, $field, $rowID, $form_atomic_Cls_map);
17 $asset_url = BITFORMS_ASSET_URI;
18 $img_url = BITFORMS_ASSET_URI . '/../static/countries/';
19 $req = $fieldHelpers->required();
20 $disabled = $fieldHelpers->disabled();
21 $readonly = $fieldHelpers->readonly();
22 $name = $fieldHelpers->name();
23 $ariaDescribedBy = $fieldHelpers->ariaDescribedBy();
24 $ariaRequired = $fieldHelpers->ariaRequired();
25 $selectedFlagImage = '';
26 $tabIndx = isset($field->disabled) ? -1 : 0;
27 $selectedCountryClearable = '';
28 $searchPlaceholder = '';
29 $searchClearable = '';
30 $options = '';
31 $readonlyCls = isset($field->readonly) ? 'readonly' : '';
32 $disabledCls = isset($field->disabled) ? 'disabled' : '';
33 $val = $fieldHelpers->value();
34
35 $selectedItm = null;
36 foreach ($field->options as $opt) {
37 if (isset($opt->check) && true === $opt->check) {
38 $selectedItm = $opt;
39 break;
40 }
41 }
42 if ($selectedItm) {
43 $img = $img_url . $selectedItm->img;
44 $ph = $selectedItm->lbl;
45 } else {
46 $img = esc_url(includes_url('images/blank.gif'));
47 $ph = isset($field->ph) ? $field->ph : '';
48 }
49
50 if ($fieldHelpers->property_exists_nested($field, 'config->selectedFlagImage', true)) {
51 $img = sprintf(
52 '<img
53 %1$s
54 class="%2$s %3$s"
55 aria-hidden="true"
56 alt="selected country flag"
57 src="%4$s"
58 >
59 ',
60 $fieldHelpers->getCustomAttributes('selected-country-img'),
61 $fieldHelpers->getConversationalMultiCls('selected-country-img'),
62 $fieldHelpers->getCustomClasses('selected-country-img'),
63 $img
64 );
65 } else {
66 $img = '';
67 }
68
69 $selectedFlagImage = sprintf(
70 '<div class="%1$s">
71 %2$s
72 <span
73 %3$s
74 class="%4$s %5$s"
75 >
76 %6$s
77 </span>
78 </div>
79 ',
80 $fieldHelpers->getConversationalMultiCls('selected-country-wrp'),
81 $img,
82 $fieldHelpers->getCustomAttributes('selected-country-lbl'),
83 $fieldHelpers->getConversationalMultiCls('selected-country-lbl'),
84 $fieldHelpers->getCustomClasses('selected-country-lbl'),
85 $fieldHelpers->esc_html($ph)
86 );
87
88 if ($fieldHelpers->property_exists_nested($field, 'config->selectedCountryClearable', true)) {
89 $selectedCountryClearable = sprintf(
90 ' <button
91 %1$s
92 type="button"
93 title="Clear selected country value"
94 class="%2$s %3$s"
95 >
96 <svg
97 width="15"
98 height="15"
99 role="img"
100 title="Cross icon"
101 viewBox="0 0 24 24"
102 fill="none"
103 stroke="currentColor"
104 stroke-width="2"
105 stroke-linecap="round"
106 stroke-linejoin="round"
107 >
108 <line x1="18" y1="6" x2="6" y2="18" />
109 <line x1="6" y1="6" x2="18" y2="18" />
110 </svg>
111 </button>
112 ',
113 $fieldHelpers->getCustomAttributes('inp-clr-btn'),
114 $fieldHelpers->getConversationalMultiCls('inp-clr-btn'),
115 $fieldHelpers->getCustomClasses('inp-clr-btn')
116 );
117 }
118
119 if ($fieldHelpers->property_exists_nested($field, 'config->searchPlaceholder', '', 1)) {
120 $searchPlaceholder = "placeholder='{$fieldHelpers->esc_attr($field->config->searchPlaceholder)}'";
121 }
122
123 if ($fieldHelpers->property_exists_nested($field, 'config->searchClearable', true)) {
124 $searchClearable = sprintf(
125 '<button
126 %1$s
127 type="button"
128 title="Clear search"
129 class="%2$s %3$s %4$s"
130 tabIndex="-1"
131 >
132 <svg
133 width="13"
134 height="13"
135 role="img"
136 title="Cross icon"
137 viewBox="0 0 24 24"
138 fill="none"
139 stroke="currentColor"
140 stroke-width="2"
141 stroke-linecap="round"
142 stroke-linejoin="round"
143 >
144 <line x1="18" y1="6" x2="6" y2="18" />
145 <line x1="6" y1="6" x2="18" y2="18" />
146 </svg>
147 </button>
148 ',
149 $fieldHelpers->getCustomAttributes('search-clear-btn'),
150 $fieldHelpers->getConversationalMultiCls('icn'),
151 $fieldHelpers->getConversationalMultiCls('search-clear-btn'),
152 $fieldHelpers->getCustomClasses('search-clear-btn')
153 );
154 }
155
156 return ' <div class="' . $fieldHelpers->getConversationalMultiCls('country-fld-container') . '">
157 <div
158 ' . $fieldHelpers->getCustomAttributes('country-fld-wrp') . '
159 class="' . $fieldHelpers->getConversationalMultiCls('country-fld-wrp') . ' ' . $fieldHelpers->getCustomClasses('country-fld-wrp') . ' ' . $disabled . ' ' . $readonly . '"
160 >
161 <input
162 ' . $name . '
163 ' . $req . '
164 ' . $ariaRequired . '
165 ' . $ariaDescribedBy . '
166 type="text"
167 title="Country Hidden Input"
168 class="' . $fieldHelpers->getConversationalMultiCls('country-hidden-input') . ' d-none"
169 ' . $disabled . '
170 ' . $readonly . '
171 ' . $val . '
172 />
173 <div
174 class="' . $fieldHelpers->getConversationalMultiCls('dpd-wrp') . '"
175 aria-live="assertive"
176 aria-label="Select a Country"
177 role="combobox"
178 aria-haspopup="listbox"
179 aria-expanded="false"
180 tabIndex=' . $tabIndx . '
181 >
182 ' . $selectedFlagImage . '
183
184 <div class="' . $fieldHelpers->getConversationalMultiCls('dpd-btn-wrp') . '">
185 ' . $selectedCountryClearable . '
186 <div class="' . $fieldHelpers->getConversationalMultiCls('dpd-down-btn') . '">
187 <svg
188 width="15"
189 height="15"
190 viewBox="0 0 24 24"
191 title="Cross icon"
192 role="img"
193 fill="none"
194 stroke="currentColor"
195 stroke-width="2"
196 stroke-linecap="round"
197 stroke-linejoin="round"
198 >
199 <polyline points="6 9 12 15 18 9" />
200 </svg>
201 </div>
202 </div>
203 </div>
204 <div
205 ' . $fieldHelpers->getCustomAttributes('option-wrp') . '
206 class="' . $fieldHelpers->getConversationalMultiCls('option-wrp') . ' ' . $fieldHelpers->getCustomClasses('option-wrp') . '"
207 >
208 <div class="' . $fieldHelpers->getConversationalMultiCls('option-inner-wrp') . '">
209 <div class="' . $fieldHelpers->getConversationalMultiCls('option-search-wrp') . '">
210 <input
211 ' . $fieldHelpers->getCustomAttributes('opt-search-input') . '
212 type="search"
213 class="' . $fieldHelpers->getConversationalMultiCls('opt-search-input') . ' ' . $fieldHelpers->getCustomClasses('opt-search-input') . '"
214 ' . $searchPlaceholder . '
215 autoComplete="country-name"
216 tabIndex="-1"
217 />
218 <svg
219 ' . $fieldHelpers->getCustomAttributes('opt-search-icn') . '
220 class="' . $fieldHelpers->getConversationalMultiCls('icn') . ' ' . $fieldHelpers->getConversationalMultiCls('opt-search-icn') . ' ' . $fieldHelpers->getCustomClasses('opt-search-icn') . '"
221 aria-hidden="true"
222 width="22"
223 height="22"
224 role="img"
225 title="Search icon"
226 viewBox="0 0 24 24"
227 fill="none"
228 stroke="currentColor"
229 stroke-width="2"
230 stroke-linecap="round"
231 stroke-linejoin="round"
232 >
233 <circle cx="11" cy="11" r="8" />
234 <line x1="21" y1="21" x2="16.65" y2="16.65" />
235 </svg>
236 ' . $searchClearable . '
237 </div>
238 <ul
239 ' . $fieldHelpers->getCustomAttributes('option-list') . '
240 class="' . $fieldHelpers->getConversationalMultiCls('option-list') . ' ' . $fieldHelpers->getCustomClasses('option-list') . '"
241 tabIndex="-1"
242 role="listbox"
243 aria-label="country list"
244 >
245 ' . $options . '
246 </ul>
247 </div>
248 </div>
249 </div>
250 </div>';
251 }
252 }
253