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

No longer reactive with Livewire. #8

Open vahnmarty opened 2 years ago

vahnmarty commented 2 years ago
Screen Shot 2022-02-09 at 1 33 30 AM
<x-tel-input wire:model="test"  id="phone"/>
                {{ $test }}

In Livewire

{

 public $test = '1234';
}
ousid commented 2 years ago

Hey, @vahnmarty

Can you share some details about the implementation of laravel-tel-input inside your project?

stojankukrika commented 2 years ago

I also have issue in liveware component:

<x-tel-input wire:model="phone" id="phone" name="phone" class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-white focus:border-easyvation-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-800 dark:focus:shadow-outline-gray form-input form-input" />

and when submit the form I get an empty string for the phone.

stojankukrika commented 2 years ago

even do not send request on type numbers like in other form fields...

Geovanek commented 2 years ago

For me there was also no reactivity from wire:model="phone".

document.addEventListener("livewire:load", () => {
    phone.addEventListener('telchange', function(e) {
        window.Livewire.emit('telchange', e.detail);
    });
});

And in the component I did like this:

public $phone;
public $phoneValid;

protected $listeners = [
    'telchange',
];

public function telchange($telchange)
    {
        $this->phoneValid = $telchange['valid'];
        $this->phone = $telchange['number'];
    }

    public function register()
    {
        $this->withValidator(function (Validator $validator) {
            $validator->after(function ($validator) {
                if ($this->phone === '') {
                    $validator->errors()->add('phone', __('O campo telefone é obrigatório.'));
                }
                if ($this->phoneValid === false) {
                    $validator->errors()->add('phone', __('Número de telefone inválido.'));
                }
            });
        })->validate();
    ...

On blade:

    <div class="form-group">
            <label for="phone">{{ __('Phone') }}</label>
            <x-tel-input wire:model.lazy="phone"
                id="phone" name="phone"
                class="form-control-rounded form-control"/>
            @error('phone')
                <span class="invalid-feedback" role="alert" style="display: block">
                    <strong>{{ $message }}</strong>
                </span>
            @enderror
    </div>