Skip to content

Commit 5d579a7

Browse files
committed
Added support for Livewire 3
1 parent fa13596 commit 5d579a7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Laravel Telephone Input component for Blade and Livewire based on the [intl-tel-
2828
- [Usage](#usage)
2929
- [Basic usage](#basic-usage)
3030
- [Add hidden phone-country-input](#add-hidden-phone-country-input)
31-
- [Usage with Livewire](#usage-with-livewire)
31+
- [Usage with Livewire 2](#usage-with-livewire-2)
32+
- [Usage with Livewire 3](#usage-with-livewire-3)
3233
- [Sync tel-input wih a country dropdown](#sync-tel-input-wih-a-country-dropdown)
3334
- [Event Listener](#event-listener)
3435
- [Props / Attributes](#props--attributes)
@@ -151,7 +152,7 @@ Please refer to the [intl-tel-input readme](https://github.com/jackocnr/intl-tel
151152
/>
152153
<input type="hidden" id="phone_country" name="phone_country">
153154
```
154-
##### Usage with Livewire
155+
##### Usage with Livewire 2
155156
```html
156157
<x-tel-input
157158
wire:model="phone"
@@ -161,6 +162,17 @@ Please refer to the [intl-tel-input readme](https://github.com/jackocnr/intl-tel
161162
/>
162163
<input wire:model="phone_country" type="hidden" id="phone_country" name="phone_country">
163164
```
165+
##### Usage with Livewire 3
166+
```html
167+
<x-tel-input
168+
wire:model.live="phone"
169+
value="{{ $phone }}"
170+
id="phone"
171+
name="phone"
172+
class="form-input"
173+
/>
174+
<input wire:model="phone_country" type="hidden" id="phone_country" name="phone_country">
175+
```
164176
##### Sync tel-input wih a country dropdown
165177
```html
166178
<div class="form-item">
@@ -246,7 +258,8 @@ input.addEventListener('telchange', function(e) {
246258
$this->showQuickContactForm = !$this->showQuickContactForm;
247259

248260
if ($this->showQuickContactForm) {
249-
$this->dispatchBrowserEvent('telDOMChanged');
261+
$this->dispatchBrowserEvent('telDOMChanged'); // in Livewire 2
262+
$this->dispatch('telDOMChanged'); // in Livewire 3
250263
}
251264
}
252265
//...

resources/js/laravel-tel-input.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
}
158158
}
159159

160-
// countrychange event function
160+
// tel input change event function
161161
const telInputChangeEventFunc = function () {
162162
// phone input data
163163
if (this.dataset.phoneInput) {
@@ -182,6 +182,7 @@
182182
}
183183
if (phoneInput.value !== oldValue && phoneInput.value != '' && (itiPhone.isValidNumber() === true || itiPhone.isValidNumber() === null)) {
184184
phoneInput.dispatchEvent(new KeyboardEvent('change'));
185+
phoneInput.dispatchEvent(new KeyboardEvent('input'));
185186
phoneInput.dispatchEvent(new CustomEvent('telchange', {
186187
detail: {
187188
valid: true,
@@ -195,6 +196,7 @@
195196
} else {
196197
if (itiPhone.isValidNumber() === false) {
197198
phoneInput.dispatchEvent(new KeyboardEvent('change'));
199+
phoneInput.dispatchEvent(new KeyboardEvent('input'));
198200
phoneInput.dispatchEvent(new CustomEvent('telchange', {
199201
detail: {
200202
valid: false,

0 commit comments

Comments
 (0)