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>
js$('#picker').mobiscroll().datepicker({
controls: ['date']
});
html<label>
Custom default
<input id="picker" mbsc-input placeholder="Please select..." />
</label>
js$('#picker').mobiscroll().datepicker({
controls: ['date'],
defaultSelection: new Date(2020, 11, 24)
});
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>
js$('#today').click(function () {
$('#cal').mobiscroll('setVal', new Date());
return false;
});
$('#jan').click(function () {
$('#cal').mobiscroll('setVal', new Date(2020, 0, 2));
return false;
}); 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>
Auto set
<input id="picker" mbsc-input placeholder="Please select..." />
</label>
js$('#picker').mobiscroll().datepicker({
controls: ['date'],
buttons: [{
text: 'Close',
handler: 'cancel'
}]
});