datepicker initial date

Should be easy, but I can't find a way to set the landing date of the datepicker, trying:
DatePicker::make('uc_dob')
->required()
->label('Date of Birth')
->displayFormat(Date::FORMAT_DATE_HUMAN)
->default(now()->subYears(45))
->visible(fn ($record) : bool => $record->uc_dob == false)
->minDate(now()->subYears(90))
->maxDate(now()->subYears(18)),
DatePicker::make('uc_dob')
->required()
->label('Date of Birth')
->displayFormat(Date::FORMAT_DATE_HUMAN)
->default(now()->subYears(45))
->visible(fn ($record) : bool => $record->uc_dob == false)
->minDate(now()->subYears(90))
->maxDate(now()->subYears(18)),
I've checked uc_dob is null Thanks
4 Replies
ChesterS
ChesterS4mo ago
If this is editing a record, default might now work AFAIK. You need another way to set the datepicker value if it's null.
Matthew
MatthewOP4mo ago
Hi, In this example, it is an edit. But I'm surprised that this is not already a well required function.
default
default
doesn't appear to work.
ChesterS
ChesterS4mo ago
Well, it doesn't make much sense having a default value during an edit. For example if someone opened that form and hit 'Save', the data would change even if they didn't change anything. Anyway, it's better if you do that manually using something like https://filamentphp.com/docs/3.x/forms/advanced#field-hydration
Matthew
MatthewOP4mo ago
I'll check those docs. But it is not about having a default value as such, it is where the datepicker starts. The datepicker opens up on, (when there is no pre-exisiting value), at the latest date it can. In my example
now()->subYears(18)
now()->subYears(18)
I want it to open up on
now()->subYears(45)
now()->subYears(45)
(unless there is pre-existing data, in which case it opens up on that, which works fine)
Want results from more Discord servers?
Add your server