0

In most browsers I can do the following

const x = document.getElementById("asdf");
x.addEventListener("focus", () => {
  x.type = 'date'
})
x.addEventListener("blur", () => {
  x.type = 'text'
})
<input type="text" id="asdf" placeholder="foop" />

However on mobile Safari it does not show the proper date picker when I tap on the field.

Is there anything I can do?

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265

1 Answers1

0

The work around I eventually put in was to create two input fields

const x = document.getElementById("asdf");
const y = document.getElementById("asdf-date");
x.addEventListener("focus", () => {
  x.style.display = "none";
  y.style.display = "initial";
  y.focus();
})
x.addEventListener("blur", () => {
  x.style.display = "initial";
  y.style.display = "none";
  x.value = y.value;
})
<input type="text" id="asdf" placeholder="foop" />
<input type="text" id="asdf-date" style="display:none" placeholder="foop" />
Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265