| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Frontend\Form\View\Theme\Fields; |
| 4 |
|
| 5 |
class PhoneNumberField |
| 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 |
$img_url = BITFORMS_ASSET_URI . '/../static/countries/'; |
| 18 |
$req = $fh->required(); |
| 19 |
$disabled = $fh->disabled(); |
| 20 |
$readonly = $fh->readonly(); |
| 21 |
$name = $fh->name(); |
| 22 |
$ph = $fh->placeholder(); |
| 23 |
$selectedFlagImage = ''; |
| 24 |
$dropDownBtn = ''; |
| 25 |
$tabIndx = isset($field->disabled) ? -1 : 0; |
| 26 |
$selectedCountryClearable = ''; |
| 27 |
$dpdWrap = ''; |
| 28 |
$searchPlaceholder = ''; |
| 29 |
$searchClearable = ''; |
| 30 |
$optionWrap = ''; |
| 31 |
$options = ''; |
| 32 |
$showSelectedFlagImg = $fh->property_exists_nested($field, 'config->selectedFlagImage', true); |
| 33 |
$hideCountryList = $fh->property_exists_nested($field, 'config->hideCountryList', true); |
| 34 |
$readonlyCls = isset($field->readonly) ? 'readonly' : ''; |
| 35 |
$disabledCls = isset($field->disabled) ? 'disabled' : ''; |
| 36 |
$img = htmlentities("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>"); |
| 37 |
|
| 38 |
$val = $fh->value(); |
| 39 |
|
| 40 |
if ($showSelectedFlagImg) { |
| 41 |
$selectedFlagImage = sprintf( |
| 42 |
'<div class="%1$s"> |
| 43 |
<img |
| 44 |
%2$s |
| 45 |
alt="Selected Country image" |
| 46 |
aria-hidden="true" |
| 47 |
class="%3$s %4$s" |
| 48 |
src="%5$s" |
| 49 |
/> |
| 50 |
</div>', |
| 51 |
$fh->getAtomicCls('selected-country-wrp'), |
| 52 |
$fh->getCustomAttributes('selected-phone-img'), |
| 53 |
$fh->getAtomicCls('selected-country-img'), |
| 54 |
$fh->getCustomClasses('selected-country-img'), |
| 55 |
$img |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
if (!$hideCountryList) { |
| 60 |
$dropDownBtn = sprintf( |
| 61 |
'<div class="%1$s"> |
| 62 |
<svg |
| 63 |
width="15" |
| 64 |
height="15" |
| 65 |
role="img" |
| 66 |
title="Downarrow icon" |
| 67 |
viewBox="0 0 24 24" |
| 68 |
fill="none" |
| 69 |
stroke="currentColor" |
| 70 |
stroke-width="2" |
| 71 |
stroke-linecap="round" |
| 72 |
stroke-linejoin="round" |
| 73 |
> |
| 74 |
<polyline points="6 9 12 15 18 9" /> |
| 75 |
</svg> |
| 76 |
</div>', |
| 77 |
$fh->getAtomicCls('dpd-down-btn') |
| 78 |
); |
| 79 |
} |
| 80 |
|
| 81 |
if ($fh->property_exists_nested($field, 'config->selectedCountryClearable', true)) { |
| 82 |
$selectedCountryClearable = sprintf( |
| 83 |
'<button |
| 84 |
%1$s |
| 85 |
type="button" |
| 86 |
title="Clear value" |
| 87 |
class="%2$s %3$s" |
| 88 |
> |
| 89 |
<svg |
| 90 |
width="12" |
| 91 |
height="12" |
| 92 |
viewBox="0 0 24 24" |
| 93 |
fill="none" |
| 94 |
stroke="currentColor" |
| 95 |
stroke-width="2" |
| 96 |
stroke-linecap="round" |
| 97 |
stroke-linejoin="round" |
| 98 |
> |
| 99 |
<line x1="18" y1="6" x2="6" y2="18" /> |
| 100 |
<line x1="6" y1="6" x2="18" y2="18" /> |
| 101 |
</svg> |
| 102 |
</button>', |
| 103 |
$fh->getCustomAttributes('input-clear-btn'), |
| 104 |
$fh->getAtomicCls('input-clear-btn'), |
| 105 |
$fh->getCustomClasses('input-clear-btn') |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
if ($fh->property_exists_nested($field, 'config->searchPlaceholder', '', 1)) { |
| 110 |
$searchPlaceholder = "{$field->config->searchPlaceholder}"; |
| 111 |
} |
| 112 |
|
| 113 |
if ($fh->property_exists_nested($field, 'config->searchClearable', true)) { |
| 114 |
$searchClearable = sprintf( |
| 115 |
'<button |
| 116 |
%1$s |
| 117 |
type="button" |
| 118 |
aria-label="Clear search" |
| 119 |
class="%2$s %3$s" |
| 120 |
tabIndex="-1" |
| 121 |
> |
| 122 |
<svg |
| 123 |
width="12" |
| 124 |
height="12" |
| 125 |
viewBox="0 0 24 24" |
| 126 |
fill="none" |
| 127 |
stroke="currentColor" |
| 128 |
stroke-width="2" |
| 129 |
stroke-linecap="round" |
| 130 |
stroke-linejoin="round" |
| 131 |
> |
| 132 |
<line x1="18" y1="6" x2="6" y2="18" /> |
| 133 |
<line x1="6" y1="6" x2="18" y2="18" /> |
| 134 |
</svg> |
| 135 |
</button>', |
| 136 |
$fh->getCustomAttributes('search-clear-btn'), |
| 137 |
$fh->getAtomicCls('search-clear-btn'), |
| 138 |
$fh->getCustomClasses('search-clear-btn') |
| 139 |
); |
| 140 |
} |
| 141 |
|
| 142 |
if (!$hideCountryList || $showSelectedFlagImg) { |
| 143 |
$dpdWrap = sprintf( |
| 144 |
'<div |
| 145 |
class="%1$s" |
| 146 |
role="combobox" |
| 147 |
aria-live="assertive" |
| 148 |
aria-labelledby="country-label-2" |
| 149 |
aria-expanded="false" |
| 150 |
tabIndex=%2$s |
| 151 |
> |
| 152 |
%3$s |
| 153 |
%4$s |
| 154 |
</div>', |
| 155 |
$fh->getAtomicCls('dpd-wrp'), |
| 156 |
$tabIndx, |
| 157 |
$selectedFlagImage, |
| 158 |
$dropDownBtn |
| 159 |
); |
| 160 |
} |
| 161 |
|
| 162 |
if (!$hideCountryList) { |
| 163 |
$optionWrap = sprintf( |
| 164 |
'<div |
| 165 |
%1$s |
| 166 |
class="%2$s %3$s" |
| 167 |
> |
| 168 |
<div class="%4$s"> |
| 169 |
<div |
| 170 |
%5$s |
| 171 |
class="%6$s %7$s" |
| 172 |
> |
| 173 |
<input |
| 174 |
%8$s |
| 175 |
aria-label="Search for countries" |
| 176 |
type="search" |
| 177 |
class="%9$s %10$s" |
| 178 |
placeholder="%11$s" |
| 179 |
autoComplete="off" |
| 180 |
tabIndex="-1" |
| 181 |
/> |
| 182 |
<svg |
| 183 |
%12$s |
| 184 |
class="%13$s %14$s" |
| 185 |
aria-hidden="true" |
| 186 |
width="22" |
| 187 |
height="22" |
| 188 |
viewBox="0 0 24 24" |
| 189 |
fill="none" |
| 190 |
stroke="currentColor" |
| 191 |
stroke-width="2" |
| 192 |
stroke-linecap="round" |
| 193 |
stroke-linejoin="round" |
| 194 |
> |
| 195 |
<circle cx="11" cy="11" r="8" /> |
| 196 |
<line x1="21" y1="21" x2="16.65" y2="16.65" /> |
| 197 |
</svg> |
| 198 |
%15$s |
| 199 |
</div> |
| 200 |
<ul |
| 201 |
%16$s |
| 202 |
class="%17$s %18$s" |
| 203 |
tabIndex="-1" |
| 204 |
role="listbox" |
| 205 |
aria-label="country list" |
| 206 |
> |
| 207 |
%19$s |
| 208 |
</ul> |
| 209 |
</div> |
| 210 |
</div>', |
| 211 |
$fh->getCustomAttributes('option-wrp'), |
| 212 |
$fh->getAtomicCls('option-wrp'), |
| 213 |
$fh->getCustomClasses('option-wrp'), |
| 214 |
$fh->getAtomicCls('option-inner-wrp'), |
| 215 |
$fh->getCustomAttributes('option-search-wrp'), |
| 216 |
$fh->getAtomicCls('option-search-wrp'), |
| 217 |
$fh->getCustomClasses('option-search-wrp'), |
| 218 |
$fh->getCustomAttributes('opt-search-input'), |
| 219 |
$fh->getAtomicCls('opt-search-input'), |
| 220 |
$fh->getCustomClasses('opt-search-icn'), |
| 221 |
$fh->esc_attr($searchPlaceholder), |
| 222 |
$fh->getCustomAttributes('opt-search-icn'), |
| 223 |
$fh->getAtomicCls('opt-search-icn'), |
| 224 |
$fh->getCustomClasses('opt-search-icn'), |
| 225 |
$searchClearable, |
| 226 |
$fh->getCustomAttributes('option-list'), |
| 227 |
$fh->getAtomicCls('option-list'), |
| 228 |
$fh->getCustomClasses('option-list'), |
| 229 |
$options |
| 230 |
); |
| 231 |
} |
| 232 |
|
| 233 |
return sprintf( |
| 234 |
'<div class="%1$s"> |
| 235 |
<div |
| 236 |
%2$s |
| 237 |
class="%3$s %4$s %5$s %6$s" |
| 238 |
> |
| 239 |
<input |
| 240 |
%7$s |
| 241 |
%8$s |
| 242 |
type="text" |
| 243 |
title="Phone-number Hidden Input" |
| 244 |
class="%9$s d-none" |
| 245 |
%10$s |
| 246 |
%11$s |
| 247 |
%12$s |
| 248 |
/> |
| 249 |
<div class="%13$s"> |
| 250 |
%14$s |
| 251 |
<input |
| 252 |
%15$s |
| 253 |
aria-label="Phone Number" |
| 254 |
type="tel" |
| 255 |
class="%16$s %17$s" |
| 256 |
autoComplete="tel" |
| 257 |
%18$s |
| 258 |
tabIndex=%19$s |
| 259 |
/> |
| 260 |
%20$s |
| 261 |
</div> |
| 262 |
%21$s |
| 263 |
</div> |
| 264 |
</div>', |
| 265 |
$fh->getAtomicCls('phone-fld-container'), |
| 266 |
$fh->getCustomAttributes('phone-fld-wrp'), |
| 267 |
$fh->getAtomicCls('phone-fld-wrp'), |
| 268 |
$fh->getCustomClasses('phone-fld-wrp'), |
| 269 |
$readonly, |
| 270 |
$disabled, |
| 271 |
$name, |
| 272 |
$req, |
| 273 |
$fh->getAtomicCls('phone-hidden-input'), |
| 274 |
$fh->disabled(), |
| 275 |
$fh->readonly(), |
| 276 |
$val, |
| 277 |
$fh->getAtomicCls('phone-inner-wrp'), |
| 278 |
$dpdWrap, |
| 279 |
$fh->getCustomAttributes('phone-number-input'), |
| 280 |
$fh->getAtomicCls('phone-number-input'), |
| 281 |
$fh->getCustomClasses('phone-number-input'), |
| 282 |
$ph, |
| 283 |
$tabIndx, |
| 284 |
$selectedCountryClearable, |
| 285 |
$optionWrap |
| 286 |
); |
| 287 |
} |
| 288 |
} |
| 289 |
|