Disclaimer: I know there are already a few questions regarding coupling Livewire and flatpickr, yet I don’t understand the solutions provided, since they are very different from how I’m approaching the problem. That said, I’m still learning Livewire, so I might just be doing it wrong.
I have a Livewire component where I use flatpickr to select both date and time.
<div class="mb-3" >
<input id="chosendatetime" type="datetime-local" name="chosendatetime" value="{{ old('chosendatetime') }}"
wire:model.debounce.500ms="chosendatetime" />
</div>
In the blade component, I have also the script section to init flatpickr:
<script>
flatpickr("#chosendatetime", {
enableTime: true,
dateFormat: "d-m-Y H:i",
});
</script>
The date picker is rendered correctly, but when I change its value the data sent by the client is empty.
What should I do?
2
Answers
Your code is working fine, IF you have setup your Livewire properly.
public $chosendatetime;
dd()
the $this->chosendatetime to see if the value is received or not@livewireStyles
and@livewireScripts
inside your layout blade.The Livewire class will look like
try to add
wire:ignore
to the div element, like this:This directive lets Livewire know that it should skip this part of the page and not change it when the component refreshes. If you don’t use it, Livewire could replace the flatpickr instance and make it stop working.