Disclaimer: I know there have been some questions about how to couple Livewire and flatpickr, but I don't understand the solutions provided because they are very different from how I approach the problem. Having said that, I'm still learning Livewire, so I might just be doing it wrong.
I have a Livewire component in which I use flatpickr to select a 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 also have a script section for initializing 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?
Your code runs fine if you set up Livewire correctly.
public $chosendatetime;
$this->chosendatetime
using dd() to see if the value was received@livewireStyles
and@livewireScripts
The code of the Livewire class is as follows:
Try adding
wire:ignore
to the div element like this:This directive tells Livewire that this part of the page should be skipped and not changed when the component refreshes. If you don't use it, Livewire may replace the flatpickr instance and make it stop working.