Date Picker Placeholder
I'm trying to set up a placeholder for a Date Picker input inside a form, but it does not seem to work, even though the documentation for v3 says it should.
I have tried passing a datetime string, a Carbon date, but to no avail.
Thanks in advance for your help!
8 Replies
What code are you trying?
DatePicker::make('starts')->placeholder(Carbon::now()->toDateString)
I tried passing the Carbon object itself, and hardcoded a simple datetime string. I also tried a string that matches the formatting on the front-end (because why not), but it did not work either.Placeholder seems weird to me on a DatePicker. But maybe try it as a callback. ->placholder(fn () => now()->toDateString())
I’m not even sure a date picker has a placeholder at the html level.
You're right, seems like placeholder don't apply to date pickers.
Thought I saw it in the documentation, but I realized it was v1, not v3.
Maybe you could get what you want with ->default() but that will only work in the create context.
It does work with default, but somehow the value is set only after the state is mutated on the front-end.
So, set it in afterStateHydrated()
If null set the state to now()
OK, I've got the behavior I wanted. Thank you so much for your help, have a great day!