onViewChange( )


Adds an event handler that triggers when the date picker's view changes.

When a site visitor views a new month or year in the date picker, the event handler is triggered. Selecting a new day in the current month doesn't trigger the event handler, as the month in view doesn't change. Each time a site visitor enters the date picker, they initiate the view, triggering the event handler. You can pass an optional operation() function parameter. If provided, the operation() function is called first, and the handler function only triggers after the operation finishes. You can pass an optional timeout parameter to specify how long to wait for the operation to return. If the operation doesn't resolve before the timeout, an error is returned. When the operation() function returns, the returned object is passed to the event handler in the options.operationResult object.

Note: The operation() function is called each time the month or year changes and the onViewChange event is triggered. If the operation() function takes time to return, there can be more than one instance of the function running when a site visitor clicks multiple times on the next month arrow. In these cases, only the last triggered operation is returned to the event handler and the handler only runs once. For example, if the date picker's view is in May, and a site visitor clicks the next month arrow 3 times, the operation function is called for June, July, and August. However, the handler is only called only once with the result from the operation for August.

Method Declaration
Copy
Method Parameters
handlerfunctionRequired

handler(event: ViewChangeEvent): void Name of the function or the function expression that is called when the date picker's view changes.


operationfunction

operation(options: OperationOptions): any Name of an async operation that is called when the date picker's view changes. The operation result is passed to the handler in the event's options.operationResult object.


timeoutnumber

Number of milliseconds to wait for the operation() function to return. If the operation doesn't resolve before the timeout, an error is returned. Defaults to 10,000.

Did this help?