Skip to content

Commit af502e7

Browse files
committed
Fix tel-input not rendering in Livewire after component update, refresh or change in DOM content.
1 parent b581029 commit af502e7

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-tel-input` will be documented in this file
44

5+
## v1.1.5 - 2021-09-28
6+
7+
- Fix tel-input not rendering in Livewire after component update, refresh or change in DOM content.
8+
-
59
## v1.1.4 - 2021-09-27
610

711
- Fix utilsScript relative path bug

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Laravel Telephone Input component for Blade and Livewire based on the [intl-tel-
3333
- [Event Listener](#event-listener)
3434
- [Props / Attributes](#props--attributes)
3535
- [Events](#events)
36+
- [Troubleshooting](#troubleshooting)
3637
- [Testing](#testing)
3738
- [Changelog](#changelog)
3839
- [Contributing](#contributing)
@@ -225,6 +226,31 @@ input.addEventListener('telchange', function(e) {
225226
| **telchange** | `telchange` | Emitted when tel input value change. See [example](#event-listener) above. |
226227

227228

229+
<a name="troubleshooting"></a>
230+
231+
## Troubleshooting
232+
233+
- ### tel-input not rendering in Livewire after component update, refresh or change in DOM content.
234+
The most common issues encountered by Livewire users has to do with Livewire's DOM diffing/patching system. This is the system that selectively updates elements that have been changed, added, or removed after every component update.
235+
For the most part, this system is reliable, but there are certain cases where Livewire is unable to properly track changes. When this happens, hopefully, a helpful error will be thrown and you can debug with the following guide.
236+
If a tel-input fails to render after component update like opening popup/modal with a `tel-input` or switch to tab section with a form containing a `tel-input`, to fix this, dispatch a `telDOMChanged` browser event in the action that triggers/opens the popup or form tab.
237+
```php
238+
class ContactPage extends Component
239+
{
240+
public $showQuickContactForm = false;
241+
242+
public function toggleQuickContactForm()
243+
{
244+
$this->showQuickContactForm = !$this->showQuickContactForm;
245+
246+
if ($this->showQuickContactForm) {
247+
$this->dispatchBrowserEvent('telDOMChanged');
248+
}
249+
}
250+
//...
251+
}
252+
```
253+
228254
<a name="testing"></a>
229255

230256
## Testing

public/js/laravel-tel-input.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/laravel-tel-input.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,21 @@
278278
}
279279
}
280280

281-
// Listen to the document ready event and render the tel inputs
281+
// Listen to the document events and re-render the tel inputs
282282
document.addEventListener("DOMContentLoaded", function() {
283283
renderTelInput();
284-
});
285-
286-
// Livewire hook
287-
if (window.Livewire) {
288-
window.Livewire.hook('component.initialized', component => {
284+
285+
// user dispatched browser events to re-render the tel inputs
286+
document.addEventListener("telDOMChanged", function() {
289287
renderTelInput();
290288
});
291-
}
289+
290+
// Livewire event hook
291+
if (window.Livewire) {
292+
window.Livewire.hook('component.initialized', component => {
293+
renderTelInput();
294+
});
295+
}
296+
});
292297
//
293298
})();

0 commit comments

Comments
 (0)