Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable past time with time picker

Tags:

antd

Disable past time for today like an hour, minutes, sec etc using ant design. is there any simple solution than 'disabledHours' like minTime etc.

<TimePicker format="h:mm:ss A" disabledHours={() => [1, 2, 3]} />
like image 791
Jaison James Avatar asked Jul 25 '18 12:07

Jaison James


People also ask

How do I turn off past time in flutter?

In the Flutter date range picker, you can enable or disable the past dates by using the enablePastDates property of the calendar. When setting the enablePastDates property value as false, you can't able to select the past dates.

How do you only show time in date picker?

In the Data type Format dialog box, do one of the following: To format the control to show the date only, select the display style that you want in the Display the date like this list. To format the control to show the time only, select the display style that you want in the Display the time like this list.

What is time picker interval?

Interval Time Picker. This package modifies the default Flutter Time Picker widget by adding interval options when picking minutes. This means you can restrict the user from picking only certain intervals of minutes and you can choose to which interval of minutes the Time Picker will snap to in dial mode.


1 Answers

You should try to set the disableHours and disabledMinutes of your TimePicker:

<TimePicker
    disabledHours={this.getDisabledHours()}
    disabledMinutes={this.getDisabledMinutes()}
>

...
getDisabledHours = () => {
    var hours = [];
    for(var i =0; i < moment().hour(); i++){
        hours.push(i);
    }
    return hours;
}

getDisabledMinutes = (selectedHour) => {
    var minutes= [];
    if (selectedHour === moment().hour()){
        for(var i =0; i < moment().minute(); i++){
            minutes.push(i);
        }
    }
    return minutes;
}

And if you want to disable seconds you do the same thing with the disabledSeconds function which has a signature of function(selectedHour, selectedMinute).

like image 60
Alexandre Thyvador Avatar answered Oct 31 '22 10:10

Alexandre Thyvador