Setting values

Values can change in a couple of different ways: through defaults, interacting with the UI or programmatically. The date and time picker defaults to now, which can be easily overridden with the defaultSelection option. The values are set by interacting with the component and making a selection or it can be done programmatically by updating the bound value. Use the buttons option for showing/hiding set, cancel or add custom buttons.

Get started with this example

Demo

Controlling the default value

The calendar defaults to today if not overridden. You can however manually set a default value through the defaultSelection option.

jsx<Datepicker
    controls={['date']}
/>
jsxconst defaultSelection = new Date(2020, 11, 24);
                           
<Datepicker
    controls={['date']}
    defaultSelection={defaultSelection}
/>
Setting values runtime

While the selected value can be changed by interacting with the calendar, you can set the model value to change it programmatically.

jsxconst [val, setVal] = React.useState(null);
const setValue = (event) => {
    setVal(new Date(2020, 0, 2));
}; 
const setToday = (event) => {
    setVal(new Date());
};
                            
<Button onClick={setValue}>02-01-2020</Button>
<Button onClick={setToday}>Today</Button>
<Datepicker
    controls={['date']}
    value={val}
/>
Not all days have flights

The button API provides shortcuts to value selection and confirmation. Add 'Now' or custom button to the component or entirely remove the 'Set' button to activate auto-set, which automatically closes the dialog if a date is selected.

jsxconst [now, setNow] = React.useState();
const nowButtons = React.useMemo(() => {
    return [{
        text: 'Now',
        handler: () => {
            now.setVal(new Date());
            now.close();
        }
    }, 'set', 'cancel'];
}, [now]);
                            
<Datepicker
    controls={['date']}
    buttons={nowButtons}
    ref={setNow}
/>
jsxconst [custom, setCustom] = React.useState();
const customButtons = React.useMemo(() => {
    return [{
            text: '05 Jan 2020',
            handler: () => {
                custom.setVal(new Date(2020, 0, 5));
                custom.close();
            }
        }, 'set', 'cancel'
    ];
}, [custom]);
                            
<Datepicker
    controls={['date']}
    buttons={customButtons}
    ref={setCustom}
/>
jsxconst autoButtons = React.useMemo(() => {
    return [{
        text: 'Close',
        handler: 'cancel'
    }];
}, []);
                            
<Datepicker
    controls={['date']}
    buttons={autoButtons}
/>

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.