TimePicker

Hi Everyone, how I can make TimePicker::make('time') works with 24 hours and not 12 hours system
16 Replies
Dennis Koch
Dennis Koch5mo ago
You can set the PHP display format with ->displayFormat(). But the default should be H:i which is 24h
unicodes
unicodesOP5mo ago
I try it still same
TimePicker::make('time')
->label('Time')
->displayFormat('H:i')
->seconds(false)
->required(),
TimePicker::make('time')
->label('Time')
->displayFormat('H:i')
->seconds(false)
->required(),
No description
unicodes
unicodesOP5mo ago
@awcodes Hi, you have any idea about this? many thanks
Dennis Koch
Dennis Koch5mo ago
Please read our #✅┊rules and don't tag people!
unicodes
unicodesOP5mo ago
sorry @Dennis Koch
Aizaysi
Aizaysi5mo ago
hi could you share the full code of that file?
awcodes
awcodes5mo ago
->native(false)
unicodes
unicodesOP5mo ago
with ->native(false) works but look like this, user can't write inside text field directly wich not a good UX.
TimePicker::make('time')
->label('Time')
->displayFormat('H:i')
->native(false)
->seconds(false)
->required(),
TimePicker::make('time')
->label('Time')
->displayFormat('H:i')
->native(false)
->seconds(false)
->required(),
No description
awcodes
awcodes5mo ago
Yep. There’s caveats both ways. Native doesn’t allow disabling seconds or using a 24 hour format. That’s up to the browser at that point.
unicodes
unicodesOP5mo ago
so there is no way to make input field that accept only 00:00 format ?
awcodes
awcodes5mo ago
Not without a custom input. Could potentially do it with a TextInput and a mask. Would just need to make sure the state / casting is handled appropriately if your db field is time based.
unicodes
unicodesOP5mo ago
any example to do that with input and mask? and yes field in my DB is time
awcodes
awcodes5mo ago
Might want to add some validation around it too so you don’t get things like 32:99 Or a negative time.
unicodes
unicodesOP5mo ago
thank you so much I will try that
awcodes
awcodes5mo ago
Might even make a good plugin if you get it all working. 🙂
Want results from more Discord servers?
Add your server