Recently, I've been exploring the capabilities of ngx-bootstrap's rangeDatePicker. My current challenge involves attempting to automatically navigate to the previous month as soon as the user opens the rangeDatePicker
. To accomplish this, I have implemented a handler function that is triggered by the onShown
event.
The code snippet below illustrates how I have set up the rangeDatePicker
in my HTML:
<input id="input-range-dates" type="text" class="form-control" bsDaterangepicker #drp="bsDaterangepicker" [bsConfig]="bsConfig"
[(ngModel)]="bsRangeValue" (ngModelChange)="onChanges($event, drp)" [maxDate]="maxDate" placement="bottom"
(onShown)="handler('onShown')" (onHidden)="handler('onHidden')" readonly/>
While there are various properties defined for the rangeDatePicker
, the key one related to my issue is:
(onShown)="handler('onShown')"
In the JavaScript file, I have created the following handler function:
handler(value: string): void {
if ('onShown' === value) {
[].slice.call(document.getElementsByClassName('previous')).filter(element =>
element.innerText === '‹')[0].click(); // Navigate to the previous month
}
}
Despite my efforts, when I debug the application in Chrome, it seems like the calendar and button have not fully loaded yet, resulting in the click action failing to switch to the previous month. Can anyone provide assistance or suggestions on how to address this roadblock?