html default date picker and livewire
I have problem with default datepicker using livewire, doesn't keep the value from model, when edit a form that has date doesnt see on date picker .
I have that on my laravel livewire form:
<input type="date" wire:model.debounce.300ms="start_date"
class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md"
value="{{ Carbon\Carbon::parse($start_date)->format('Y-m-d') }}">
</div>
Look the gif that is very detailed, simply when i remove the wire:model that is necessary, it saws the date...
https://ibb.co/7y66fbT
H @chris1989
it is because $start_date is not in the Y-m-d format.
You can cast $start_date in your model
Example:
class YourModel extends Model
{
protected $casts = [
'start_date' => 'date:Y-m-d'
];
}
No doesnt work, unfortunately i tried, i have already that in my model, i think is something with livewire or bug.
@chris1989
I can reproduce this, I don't think it is a Livewire bug.
In my Livewire component
function render() {
$this->start_date = Carbon::now();
return view('.....
}
De date field is empty (just showing placeholder 'dd-mm-jjjj')
If a do
function render() {
$this->start_date = Carbon::now()->format('Y-m-d');
return view('....
}
It is showing the date (01-07-2021)
Finally it worked!!!!!!!!
Please or to participate in this conversation.