PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.1.4
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.1.4
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 3.1.4, at includes/Frontend/Form/View/Conversational/Fields/CountryField.php

254 lines 8.9 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_ROOT_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 data-field-key="' . $rowID . '"
167 type="text"
168 title="Country Hidden Input"
169 class="' . $fieldHelpers->getConversationalMultiCls('country-hidden-input') . ' d-none"
170 ' . $disabled . '
171 ' . $readonly . '
172 ' . $val . '
173 />
174 <div
175 class="' . $fieldHelpers->getConversationalMultiCls('dpd-wrp') . '"
176 aria-live="assertive"
177 aria-label="Select a Country"
178 role="combobox"
179 aria-haspopup="listbox"
180 aria-expanded="false"
181 tabIndex=' . $tabIndx . '
182 >
183 ' . $selectedFlagImage . '
184
185 <div class="' . $fieldHelpers->getConversationalMultiCls('dpd-btn-wrp') . '">
186 ' . $selectedCountryClearable . '
187 <div class="' . $fieldHelpers->getConversationalMultiCls('dpd-down-btn') . '">
188 <svg
189 width="15"
190 height="15"
191 viewBox="0 0 24 24"
192 title="Cross icon"
193 role="img"
194 fill="none"
195 stroke="currentColor"
196 stroke-width="2"
197 stroke-linecap="round"
198 stroke-linejoin="round"
199 >
200 <polyline points="6 9 12 15 18 9" />
201 </svg>
202 </div>
203 </div>
204 </div>
205 <div
206 ' . $fieldHelpers->getCustomAttributes('option-wrp') . '
207 class="' . $fieldHelpers->getConversationalMultiCls('option-wrp') . ' ' . $fieldHelpers->getCustomClasses('option-wrp') . '"
208 >
209 <div class="' . $fieldHelpers->getConversationalMultiCls('option-inner-wrp') . '">
210 <div class="' . $fieldHelpers->getConversationalMultiCls('option-search-wrp') . '">
211 <input
212 ' . $fieldHelpers->getCustomAttributes('opt-search-input') . '
213 type="search"
214 class="' . $fieldHelpers->getConversationalMultiCls('opt-search-input') . ' ' . $fieldHelpers->getCustomClasses('opt-search-input') . '"
215 ' . $searchPlaceholder . '
216 autoComplete="country-name"
217 tabIndex="-1"
218 />
219 <svg
220 ' . $fieldHelpers->getCustomAttributes('opt-search-icn') . '
221 class="' . $fieldHelpers->getConversationalMultiCls('icn') . ' ' . $fieldHelpers->getConversationalMultiCls('opt-search-icn') . ' ' . $fieldHelpers->getCustomClasses('opt-search-icn') . '"
222 aria-hidden="true"
223 width="22"
224 height="22"
225 role="img"
226 title="Search icon"
227 viewBox="0 0 24 24"
228 fill="none"
229 stroke="currentColor"
230 stroke-width="2"
231 stroke-linecap="round"
232 stroke-linejoin="round"
233 >
234 <circle cx="11" cy="11" r="8" />
235 <line x1="21" y1="21" x2="16.65" y2="16.65" />
236 </svg>
237 ' . $searchClearable . '
238 </div>
239 <ul
240 ' . $fieldHelpers->getCustomAttributes('option-list') . '
241 class="' . $fieldHelpers->getConversationalMultiCls('option-list') . ' ' . $fieldHelpers->getCustomClasses('option-list') . '"
242 tabIndex="-1"
243 role="listbox"
244 aria-label="country list"
245 >
246 ' . $options . '
247 </ul>
248 </div>
249 </div>
250 </div>
251 </div>';
252 }
253 }
254