Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

krutsednar's avatar

Laravel Livewire not mounting value from datepicker

I am using Flowbite Datepick plugin with my Livewire and Livewire Component is not mounting value of the datepicker and is NULL upon selecting date

<div class="relative max-w-sm">
		<label class="form-label mb-2 text-sm font-medium text-gray-900 dark:text-white" for="date_filed">{{ trans('cruds.leaveApplication.fields.date_filed') }}</label>
<div class="absolute py-2.5 left-0 flex items-center pl-3 pointer-events-none">
                      <svg aria-hidden="true" class="w-5 h-5 text-gray-500 dark:text-gray-400" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd"></path></svg>
                    </div>
                    <input datepicker datepicker-autohide type="text" wire:model="leaveApplication.date_filed" id="date_filed" name="date_filed" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5  dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Select date">
                    <div class="validation-message">
                        {{ $errors->first('leaveApplication.date_filed') }}
                    </div>
                </div>
0 likes
2 replies
LaryAI's avatar
Level 58

The issue might be with the datepicker plugin. Try using the wire:ignore directive to ignore the datepicker plugin and then use the wire:change directive to update the value of the leaveApplication.date_filed property. Here's an example:

<div class="relative max-w-sm">
    <label class="form-label mb-2 text-sm font-medium text-gray-900 dark:text-white" for="date_filed">{{ trans('cruds.leaveApplication.fields.date_filed') }}</label>
    <div class="absolute py-2.5 left-0 flex items-center pl-3 pointer-events-none">
        <svg aria-hidden="true" class="w-5 h-5 text-gray-500 dark:text-gray-400" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd"></path></svg>
    </div>
    <input wire:ignore datepicker datepicker-autohide type="text" id="date_filed" name="date_filed" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5  dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Select date" onchange="Livewire.emit('dateChanged', this.value)">
    <div class="validation-message">
        {{ $errors->first('leaveApplication.date_filed') }}
    </div>
</div>

@push('scripts')
    <script>
        document.addEventListener('livewire:load', function () {
            Livewire.on('dateChanged', function (value) {
                @this.set('leaveApplication.date_filed', value);
            });
        });
    </script>
@endpush

In this example, we added the wire:ignore directive to the input element to ignore the datepicker plugin. We also added the wire:change directive to the input element to emit a dateChanged event when the value of the input changes. We then added a JavaScript listener to listen for the dateChanged event and update the value of the leaveApplication.date_filed property using the @this.set directive.

Please or to participate in this conversation.