This method sets the allowed interval, that can be entered into the Date control.
Syntax
ctrl.setAllowedInterval( start, end, message: string )
Arguments
start/end
a datetime string "2001-05-12 12:22:33", a JavaScript Date or a Moment.js object. If the start/end argument is undefined, the interval has no start/end;
message
a string that appears when a date outside of the selected interval is entered into the control. If the message is undefined, a default one is displayed.
Return value
No return value.
Examples
setAllowedInterval() can be used in the JavaScript OnLoad event, as well as any other JavaScript event.
1. Allow selecting dates starting from 12/15/19 and on with a string date:
//string date
var ctrl = Runner.getControl(pageid, 'datefield');
ctrl.setAllowedInterval( '2019-12-15', null, 'error message' );
2. Allow selecting only the dates from 12/10/19 to 12/25/19 with a JS Date object:
//javascript date object
var ctrl = Runner.getControl(pageid, 'datefield');
var js_start = new Date('2019-12-10');
var js_end = new Date('2019-12-25');
ctrl.setAllowedInterval( js_start, js_end, 'error message' );
3. Allow selecting only the past dates (prior to the current one) with a Moment.js object:
//Moment.js date object
var ctrl = Runner.getControl(pageid, 'datefield');
var moment_date = moment().add(-1, 'days');
ctrl.setAllowedInterval( null, moment_date, 'error message' );
4. Allow selecting only the future dates:
//javascript date object
var ctrl = Runner.getControl(pageid, 'datefield');
var js_start = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
ctrl.setAllowedInterval( js_start, null, 'error message' );
5. Allow selecting ten days, starting with tomorrow's date:
//Moment.js date object
var ctrl = Runner.getControl(pageid, 'datefield');
var start_moment_date = moment().add(1,'days');
var end_moment_date = moment().add(11,'days');
ctrl.setAllowedInterval( start_moment_date, end_moment_date, 'error message' );
Note: replace "datefield" and "error message" with the actual field name and error message in the function.
See also:
•JavaScript API: Control object > getControl()
•JavaScript API: Date Control API > getAllowedInterval()