Flatpickr doesn’t automatically trigger an input event when a date is selected, unlike Pikaday. Instead, it uses its own onChange event, whereas Livewire relies on standard input events to detect changes.
Since wire:model.blur only updates Livewire when the field loses focus, you need to manually dispatch an input event to ensure real-time updates.
<input x-data wire:model="selectedDate" x-ref="datePickerInput"
x-init="flatpickr($refs.datePickerInput, {
dateFormat: 'd-m-Y',
onValueUpdate: (selectedDates, dateStr) => {
$refs.datePickerInput.value = dateStr; // Update input value
$dispatch('input', dateStr); // Ensure Livewire detects the change
}
})" type="text">
Note: Instead of using onChange, which triggers only when a date is fully selected, onValueUpdate ensures Livewire updates as soon as the value changes. That said, the choice depends on your specific needs.