How can I help you?
Time range in React Timepicker component
21 Feb 20265 minutes to read
The min and max properties define the valid time selection range in the TimePicker. The minimum value must be less than the maximum value.
When the min and max properties are configured and the selected time value is out-of-range or invalid, then the model value will be set to out of range time value or null respectively with highlighted error class to indicates the time is out of range or invalid.
The value property depends on the min/max with respect to strictMode property. The following example allows you to select a time value within a range of 9:00 AM to 11:30 AM.
[Class-component]
// import the ripple effect
import { enableRipple } from '@syncfusion/ej2-base';
// import the timepicker
import { TimePickerComponent } from '@syncfusion/ej2-react-calendars';
import * as React from "react";
import * as ReactDOM from "react-dom";
// enable ripple effect
enableRipple(true);
export default class App extends React.Component {
// initialize the min and max time value
minTime = (new Date('8/3/2017 9:00 AM'));
maxTime = (new Date('8/3/2017 11:30 AM'));
render() {
return <TimePickerComponent id="timepicker" placeholder="Select a Time" min={this.minTime} max={this.maxTime}/>;
}
}
;
ReactDOM.render(<App />, document.getElementById('timer'));// import the ripple effect
import { enableRipple } from '@syncfusion/ej2-base';
// import the timepicker
import { TimePickerComponent } from '@syncfusion/ej2-react-calendars';
import * as React from "react";
import * as ReactDOM from "react-dom";
// enable ripple effect
enableRipple(true);
export default class App extends React.Component<{}, {}> {
// initialize the min and max time value
private minTime: Date = (new Date('8/3/2017 9:00 AM'));
private maxTime: Date = (new Date('8/3/2017 11:30 AM'));
public render() {
return <TimePickerComponent id="timepicker" placeholder="Select a Time" min={this.minTime} max={this.maxTime} />
}
};
ReactDOM.render(<App />, document.getElementById('timer'));[Functional-component]
// import the ripple effect
import { enableRipple } from '@syncfusion/ej2-base';
// import the timepicker
import { TimePickerComponent } from '@syncfusion/ej2-react-calendars';
import * as React from "react";
import * as ReactDOM from "react-dom";
// enable ripple effect
enableRipple(true);
function App() {
// initialize the min and max time value
const minTime = (new Date('8/3/2017 9:00 AM'));
const maxTime = (new Date('8/3/2017 11:30 AM'));
return <TimePickerComponent id="timepicker" placeholder="Select a Time" min={minTime} max={maxTime}/>;
}
;
ReactDOM.render(<App />, document.getElementById('timer'));// import the ripple effect
import { enableRipple } from '@syncfusion/ej2-base';
// import the timepicker
import { TimePickerComponent } from '@syncfusion/ej2-react-calendars';
import * as React from "react";
import * as ReactDOM from "react-dom";
// enable ripple effect
enableRipple(true);
function App() {
// initialize the min and max time value
const minTime: Date = (new Date('8/3/2017 9:00 AM'));
const maxTime: Date = (new Date('8/3/2017 11:30 AM'));
return <TimePickerComponent id="timepicker" placeholder="Select a Time" min={minTime} max={maxTime} />
};
ReactDOM.render(<App />, document.getElementById('timer'));If the value of
minormaxproperty is changed through code behind you have to update thevalueproperty to set within the range.