DateTimePicker
DateTimePicker copied to clipboard
Disable Certain Days/Hours
Hello , I was wondering if there is a function in this library that allows us to disable certain days and hours? For example in the time picker 12:30 would be disabled but not hidden. Or in a different colour?
+1. This is similar but different from to intervals as time intervals is recurring ever x minutes and this is set times.
@Huddie Let's move the discussion here. I don't really see the connection between issue #43 and this one. Can you elaborate set times
? Like you want to put in an array of NSDate
whose time should be disabled in the picker?
@itsmeichigo yes! Just you put in array of times that are enabled, so if you have like a certain schedule that your users can choose a valid time but it’s not intervals. It connects because it’s restricting the times available
@Huddie Thanks for your input. I can understand your idea now but I'm not sure it's cool to input an array of times (in terms of coding design). And to let user scroll through the list with only some of the items enabled doesn't seem like good user experience either. So I'll leave the ticket open and hopefully there's someone interested in the idea and willing to help out with this case.
@itsmeichigo Hi, Is there any possibility to disable specific time interval like i want to show only 8am to 4 pm and remaining are disable to hide from user?
+1
+1
+1
As this is still open, I'm looking for the same feature. Using it to setup events but can only be within the time the venue is open.
For a quick fix, the framework doesn't need to handle arrays, at least to start with.
I've added the following variable into DateTimePicker.swift
public var doneButtonIsEnabled: Bool = true {
didSet {
doneButton.isEnabled = doneButtonIsEnabled
}
}
Then set the variable based on my own checks when dateTimePicker didSelectDate is called:
public func dateTimePicker(_ picker: DateTimePicker, didSelectDate: Date) {
if didSelectDate >= startDate && didSelectDate <= endDate {
picker.doneButtonTitle = "Choose date"
picker.doneBackgroundColor = .green
picker.doneButtonIsEnabled = true
} else {
picker.doneButtonTitle = "Venue is closed"
picker.doneBackgroundColor = .red
picker.doneButtonIsEnabled = false
}
}
Quite a crude way, but it works.