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 with the setVal method. Use the buttons option for showing/hiding set, cancel or add custom buttons.

Download and try 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.

html<label>
    Default
    <input id="picker" mbsc-input placeholder="Please select..." />
</label>
jsmobiscroll.datepicker('#picker', {
    controls: ['date']
});
html<label>
    Custom default
    <input id="picker" mbsc-input placeholder="Please select..." />
</label>
jsmobiscroll.datepicker('#picker', {
    controls: ['date'],
    defaultSelection: new Date(2020, 11, 24)
});
Setting values runtime

While the selected value can be changed by interacting with the calendar, you can use the setVal method to change it programmatically.

html<button mbsc-button id="jan">Set 02-01-2020</button>
<button mbsc-button id="today">Set today</button>
jsdocument
    .getElementById('today')
    .addEventListener('click', function () {
        instance.setVal(new Date());
    }, false);

document
    .getElementById('jan')
    .addEventListener('click', function () {
        instance.setVal(new Date(2020, 0, 2));
    }, false);
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.

html<label>
    Now
    <input id="picker" mbsc-input placeholder="Please select..." />
</label>
jsvar nowCal = mobiscroll.datepicker('#picker', {
    controls: ['date'],
    buttons: [{
        text: 'Now',
        handler: function () {
            nowCal.setVal(new Date());
            nowCal.close();
        }
    }, 'set', 'cancel']
});
html<label>
    Custom
    <input id="picker" mbsc-input placeholder="Please select..." />
</label>
jsvar customCal = mobiscroll.datepicker('#picker', {
    controls: ['date'],
    buttons: [{
            text: '05 Jan 2020',
            handler: function (event, inst) {
                customCal.setVal(new Date(2020, 0, 5));
                customCal.close();
            }
        },
        'set', 'cancel'
    ]
});
html<label>
    Auto set
    <input id="picker" mbsc-input placeholder="Please select..." />
</label>
jsmobiscroll.datepicker('#picker', {
    controls: ['date'],
    buttons: [{
        text: 'Close',
        handler: 'cancel'
    }]
});

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.