F
Filament6d 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
idkOP6d ago
This is my code
No description
LeandroFerreira
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
idkOP6d 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
Not sure if fill() will work on each livewire request
idk
idkOP6d ago
You are right, I've done it the way you provided. Thanks!!

Did you find this page helpful?