Is there a way to open an ion-datetime programatically?
in Ionic 6 the ion-datetime is open all the time, but it can be hidden using an ion-modal and ion-datetime-button like this
<ion-datetime-button #datetimeTrigger datetime="datetime"></ion-datetime-button>
<ion-modal [keepContentsMounted]="true">
<ng-template>
<ion-datetime #datetime
id="datetime"
presentation="date"
(ionChange)="newDatePicked($event)"
(ionFocus)="handleDateFocus()"
(ionBlur)="handleDateBlur()"
[firstDayOfWeek]="1">
</ion-datetime>
</ng-template>
</ion-modal>
I would like to open the date-time picker programatically because it is being triggered by an internal event
I can close it using datetime.confirm(true)
.
update I've managed to get it partially working, but involves rather more market than I was expecting
<ion-datetime-button datetime="datetime" hidden></ion-datetime-button>
<ion-button id="open-modal" hidden>X</ion-button>
<ion-modal [keepContentsMounted]="true" trigger="open-modal" (didDismiss)="didDismiss()">
....
</ion-modal>
When I want to open the dat time picker I do this
document.getElementById('open-modal').click();
This works but it seems strange that I have to have both the ion-datetime-button and the ion-button. Programatically clicking on the ion-datetime-button does nothing, and removing it from the markup ruins the display of the date picker.