stefangabos / Zebra_Datepicker

A super-lightweight, highly configurable, cross-browser date time picker jQuery plugin
https://stefangabos.github.io/Zebra_Datepicker/
Other
399 stars 183 forks source link

How to set a start and end time in the timepicker #167

Closed betheymc closed 4 years ago

betheymc commented 4 years ago

Hi, I am using the timepicker to replace the jQueryUI timepicker. However, I can't seem to be able to set a start time in which all times before it in the day are disabled. I wonder if you have a way to do that, and if not, could that be something added? I think it would be very useful to a lot of plugin users.

Thank you in advance!

stefangabos commented 4 years ago

Have a look at this - this should get you on the right track

betheymc commented 4 years ago

Okay thank you. This should help - does this code work when it is only the timepicker, and it is set in 12 hr format? Also it would be great if I could get the minutes to work this way as well.

stefangabos commented 4 years ago

the code is generic, you'll have to adapt it to suit your needs

betheymc commented 3 years ago

@stefangabos Is there a way to add an option to the plugin called something like "enabled_am_pm"? It would only apply if the format is set to include the am/pm option, and would give the user the ability to enable/disable am and/or pm. That way, if someone is trying to set start and end times in 12 hr format, they can use a combination of the enabled_am_pm option and the code you suggested here to successfully do it.

Let me know if that's something you can add.

Thank you!

~Beth

stefangabos commented 3 years ago

Setting a date format to one that has AM/PM will enable those (that means using a or A in the format; see docs for the possible format arguments)

betheymc commented 3 years ago

@stefangabos Thank you. I do have it set that way. My current format for my time fields is "H:i a". Maybe I wasn't making much sense earlier. I need a way to disable PM or AM only, like when you set enabled_hours to only certain hours, or enabled_minutes to only certain minutes.

My goal is to have two input timepickers (for start and end times), and write code so that, for example, if the user selects 2:30 PM in the first input, then the second input would automatically update so that all hours before "2" are disabled (using enabled_hours), and all minutes before "30" are disabled (using enabled_minutes). However, in 12 hr. time format, there is no enabled_ampm option, and in order to make my start and end times work correctly, I need to disable the "AM" option only, in this case.

Does that make more sense? Let me know if I can clarify more.