F
Filament3mo ago
idk

Default date of DatePicker

Hello, when I use ->default() for a DatePicker in a form filter does not work. Any solutions?
DatePicker::make('startDate')->default(now())
DatePicker::make('startDate')->default(now())
5 Replies
idk
idkOP3mo ago
This is my code
No description
LeandroFerreira
LeandroFerreira3mo ago
DatePicker::make('startDate')
->formatStateUsing(fn (?string $state) => $state ?? now()->format('Y-m-d'))
DatePicker::make('startDate')
->formatStateUsing(fn (?string $state) => $state ?? now()->format('Y-m-d'))
idk
idkOP3mo ago
Thanks, I also found out that it also works by adding the following code at the end of the form:
->fill(['startDate' => now()])
->fill(['startDate' => now()])
Which one should I use?
LeandroFerreira
LeandroFerreira3mo ago
Not sure if fill() will work on each livewire request
idk
idkOP3mo ago
You are right, I've done it the way you provided. Thanks!!

Did you find this page helpful?