DateTimePicker icon indicating copy to clipboard operation
DateTimePicker copied to clipboard

Disable Certain Days/Hours

Open siyavash4812 opened this issue 7 years ago • 9 comments

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?

siyavash4812 avatar Aug 11 '17 23:08 siyavash4812

+1. This is similar but different from to intervals as time intervals is recurring ever x minutes and this is set times.

Huddie avatar Nov 06 '17 12:11 Huddie

@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 avatar Nov 09 '17 02:11 itsmeichigo

@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 avatar Nov 09 '17 04:11 Huddie

@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 avatar Nov 09 '17 04:11 itsmeichigo

@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?

rehannali-devclan avatar Jan 10 '18 12:01 rehannali-devclan

+1

galfaroth avatar Mar 09 '18 21:03 galfaroth

+1

Kurt57 avatar Jun 14 '19 10:06 Kurt57

+1

Nikoloutsos avatar Jul 23 '19 14:07 Nikoloutsos

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.

adougies avatar Apr 01 '20 22:04 adougies