Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49309

Is there an Ionic "onload" or "ready" event? (Date picker not ready)

$
0
0

I want to set the value of an ion-datetime input programmatically.

<ion-datetime-button datetime="date"></ion-datetime-button>
<ion-modal>
      <ion-datetime label="Date" name="date" type="date" required presentation="date" id="date" tabindex="4"></ion-datetime>
</ion-modal>

When the DOM is ready I run:

function init() {
  myForm.elements["date"].value = formatDate(new Date(), "y-M-d");
}
window.addEventListener("load", init)

But this fails with:

Uncaught TypeError: Cannot set properties of undefined (setting ‘value’)

It seems the date element is not there. Adding a small delay helps:

setTimeout(() => {
  myForm.elements["date"].value = formatDate(new Date(), "y-M-d");
}, 1000);

But only sometimes. Occasionally date is still not there 1s after the DOM is ready.

Is there an equivalent “onload” event for Ionic?

This is VanillaJS and not Angular.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 49309

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>