Skip to content

Commit cab06f5

Browse files
mjauvinLukeTowers
andauthored
Add tel form field (#1440)
Documented by wintercms/docs#255 Co-authored-by: Luke Towers <git@luketowers.ca>
1 parent d69e841 commit cab06f5

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!-- Tel (Phone) -->
2+
<?php
3+
$fieldOptions = $field->options();
4+
$hasOptions = is_array($fieldOptions) && count($fieldOptions);
5+
$listId = $hasOptions ? $field->getId() . '-list' : null;
6+
?>
7+
<div class="input-group static">
8+
<span class="input-group-addon">
9+
<i class="empty wn-icon-phone"></i>
10+
</span>
11+
<?php if ($this->previewMode): ?>
12+
<?php if ($field->value): ?>
13+
<a
14+
href="tel:<?= e($field->value) ?>"
15+
target="_blank"
16+
rel="noopener noreferrer"
17+
class="form-control"
18+
>
19+
<?= e($field->value) ?>
20+
</a>
21+
<?php else: ?>
22+
<span class="form-control">&nbsp;</span>
23+
<?php endif ?>
24+
<?php else: ?>
25+
<input
26+
type="tel"
27+
id="<?= $field->getId() ?>"
28+
name="<?= $field->getName() ?>"
29+
value="<?= e($field->value) ?>"
30+
class="form-control"
31+
<?= isset($field->autocomplete) && is_string($field->autocomplete) ? 'autocomplete="' . e($field->autocomplete) . '"' : '' ?>
32+
<?= isset($field->maxlength) && is_numeric($field->maxlength) ? 'maxlength="' . e($field->maxlength) . '"' : '' ?>
33+
<?= isset($field->minlength) && is_numeric($field->minlength) ? 'minlength="' . e($field->minlength) . '"' : '' ?>
34+
<?= isset($field->pattern) && is_string($field->pattern) ? 'pattern="' . e($field->pattern) . '"' : '' ?>
35+
<?= isset($field->placeholder) && is_string($field->placeholder) ? 'placeholder="' . e($field->placeholder) . '"' : '' ?>
36+
<?= isset($field->size) && is_numeric($field->size) ? 'size="' . e($field->size) . '"' : '' ?>
37+
<?= $field->getAttributes() ?>
38+
<?= $listId ? 'list="' . e($listId) . '"' : '' ?>
39+
/>
40+
<?php if ($hasOptions): ?>
41+
<datalist id="<?= e($listId) ?>">
42+
<?php foreach ($fieldOptions as $value => $label): ?>
43+
<?php $value = is_int($value) ? $label : $value ?>
44+
<option value="<?= e($value) ?>"<?= $value !== $label ? ' label="' . e(trans($label)) . '"' : '' ?>></option>
45+
<?php endforeach ?>
46+
</datalist>
47+
<?php endif ?>
48+
<?php endif ?>
49+
</div>

0 commit comments

Comments
 (0)