Skip to content

Commit bb275d2

Browse files
author
Imani Manyara
committed
Bug fixes
1 parent 4e740a6 commit bb275d2

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

public/js/laraphone.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,13 @@ if (typeof window.intlTelInput !== 'function') {
270270
{
271271
// Call function to initialize an instance of int tel input on all elements with .iti--laraphone attribute
272272
const telInputconfig = laraphoneConfig; // laraphoneConfig will be defined in blade
273-
const telInputs = document.querySelectorAll(".iti--laraphone");
274-
if (telInputs.length > 0) {
275-
for (let i = 0; i < telInputs.length; i++) {
276-
initTelInput(telInputs[i], telInputconfig);
273+
const telInputs = document.querySelectorAll(".iti--laraphone");
274+
if (telInputs)
275+
{
276+
if (telInputs.length > 0) {
277+
for (let i = 0; i < telInputs.length; i++) {
278+
initTelInput(telInputs[i], telInputconfig);
279+
}
277280
}
278281
}
279282
}

resources/assets/js/laraphone.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,13 @@ if (typeof window.intlTelInput !== 'function') {
270270
{
271271
// Call function to initialize an instance of int tel input on all elements with .iti--laraphone attribute
272272
const telInputconfig = laraphoneConfig; // laraphoneConfig will be defined in blade
273-
const telInputs = document.querySelectorAll(".iti--laraphone");
274-
if (telInputs.length > 0) {
275-
for (let i = 0; i < telInputs.length; i++) {
276-
initTelInput(telInputs[i], telInputconfig);
273+
const telInputs = document.querySelectorAll(".iti--laraphone");
274+
if (telInputs)
275+
{
276+
if (telInputs.length > 0) {
277+
for (let i = 0; i < telInputs.length; i++) {
278+
initTelInput(telInputs[i], telInputconfig);
279+
}
277280
}
278281
}
279282
}

resources/views/components/laraphone.blade.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
$validationClass = !empty($getValidationClass($errors, $locale)) ? $getValidationClass($errors, $locale) : '';
1212
$isWired = $componentIsWired();
1313
$wiredKey = !empty($getNestedWireKey()) ? $getNestedWireKey().'.'.$name : $name;
14+
$wiredModel = $isWired && ! $hasComponentNativeLivewireModelBinding() ? ($locale ? $wiredKey . '.' . $locale : $wiredKey) : null;
1415
@endphp
1516

1617
{{-- Hidden phone input --}}
1718
<input
18-
type="hidden" {{ $attributes->wire('model') }} id="{{ $id }}" name="{{ $name }}"
19+
type="hidden"
20+
{{ $attributes->except('wire')->merge([
21+
'wire:model' => $wiredModel,
22+
]) }}
23+
24+
id="{{ $id }}" name="{{ $name }}"
1925
@if ($attributes->has('value'))
2026
value="{{ $attributes->get('value') }}"
2127
@endif
@@ -39,15 +45,15 @@
3945
<div class="{{$validationClass}} wire-validation ">
4046
<span wire:ignore>
4147
<input {{ $attributes->except('wire')->merge([
42-
'wire:model' . $getComponentLivewireModifier() => $isWired && ! $hasComponentNativeLivewireModelBinding() ? ($locale ? $wiredKey . '.' . $locale : $wiredKey) : null,
43-
'id' => $id,
44-
'class' => ' iti--laraphone form-control ' .$validationClass. ' ' . $attributes->get('class'),
45-
'type' => $type,
46-
'name' => $isWired ? null : ($locale ? $name . '[' . $locale . ']' : $name),
47-
'placeholder' => $placeholder,
48-
'data-locale' => $locale,
49-
'value' => $isWired ? null : ($value ?? ''),
50-
'aria-describedby' => $caption ? $id . '-caption' : null,
48+
'wire:model' => $wiredModel,
49+
'id' => $id,
50+
'class' => ' iti--laraphone form-control ' .$validationClass. ' ' . $attributes->get('class'),
51+
'type' => $type,
52+
'name' => $isWired ? null : ($locale ? $name . '[' . $locale . ']' : $name),
53+
'placeholder' => $placeholder,
54+
'data-locale' => $locale,
55+
'value' => $isWired ? null : ($value ?? ''),
56+
'aria-describedby' => $caption ? $id . '-caption' : null,
5157
]) }}
5258

5359
data-phone-input-id="{{ $id }}"

resources/views/scripts.blade.php

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
<script>
44
var laraphoneConfig = @json(config('laraphone'));
55
</script>
6+
7+
<script wire:ignore>
8+
document.dispatchEvent(new Event('telDOMChanged'));
9+
</script>

0 commit comments

Comments
 (0)