<x-date-picker ... /> would be a Blade Component, not a Livewire component <livewire:date-picker ... />
Mar 15, 2021
2
Level 1
Date Picker - Livewire
What is the best way to bring in a date picker using Livewire?
I have used Bootstrap for another non-Livewire form and that works well, however the values will not stick when using Livewire.
I just want something that is easy and going to work with Livewire.
I have tried the many examples online using Pikaday, but I get the following error -
InvalidArgumentException
Unable to locate a class or view for component [date-picker].
My code is as follows:
resources/views/livewire/show-report-job-hours.blade.php
<form wire:submit.prevent="submit">
<label for="date_start">Event Date</label>
<x-date-picker
wire:model="start_date"
id="start_date"
autocomplete="off"
hidden_element="hidden_start_date"
/>
resources/views/livewire/date-picker.blade.php
<div>
<input
x-data
x-ref="input"
x-init="new Pikaday({
field: $refs.input,
format:'M/D/YYYY',
onSelect: function() {
{{-- console.log(this);--}}
$('#'+$el.getAttribute('hidden_element')).val( dateToMySqlFormat(this._d) );
}
})"
type="text"
{{ $attributes }}
>
</div>
app/Http/Livewire/DatePicker.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class DatePicker extends Component
{
public function render()
{
return view('livewire.date-picker');
}
}
Please or to participate in this conversation.