victorybiz / laravel-tel-input

Laravel Telephone Input component for Blade and Livewire based on the intl-tel-input JavaScript plugin.
https://github.com/victorybiz/laravel-tel-input
MIT License
40 stars 13 forks source link

Livewire no sync #9

Open arnaudlidz opened 2 years ago

arnaudlidz commented 2 years ago

Hello,

First, thanks for this plugin.

I run in troubles with Livewire where the hidden input don't get the value from the user input. So I used your trick about refresh and it works.

But, and maybe because, the hidden input where the wire:model is can't sync with Livewire when it's updated by JS.

So I had to add theses line to get it works in my x-init : initPhone() { let vm = this; document.querySelector("#phone").addEventListener('telchange', function(e) { if(e.detail.valid) { vm.phone = e.detail.validNumber; } }); }

And phone: @entangle('phone').

Is there a better way ?

Have a nice day. Arnaud

mrsid18 commented 2 years ago

You can just use wire:model.lazy (lazy loading) and it'll work as expected.

And the hidden input will only update if the format is correct/valid.