79134516

Date: 2024-10-28 17:40:39
Score: 0.5
Natty:
Report link

Provided solutions did not work on my browser, since blur event is not triggered when the picker is closed, and change event was triggered before I remove change event from the input.

Not the ideal solution, since it relies on time, but does the work, as far as I know. (my JS code is in a class, that's why I'mm uysing "this" to store data)

  currentDateInput.addEventListener('change', async (event) => {
    //wait a bit to check if the user is typing or not
    await new Promise((resolve) => setTimeout(resolve, 100));
    if (!this.keyPressed) {
      this.changeDate(event);
    }
  });

  currentDateInput.addEventListener('keypress', async (event) => {
    console.log('keypress');
    if (event.keyCode === 13) {
      this.keyPressed = false;
      this.changeDate(event);
    } else {
      // disable change event
      this.keyPressed = true;
    }
  });

  currentDateInput.addEventListener('blur', async (event) => {
    console.log('blur');
    this.keyPressed = false;
    this.changeDate(event);
  });
Reasons:
  • Blacklisted phrase (1): did not work
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Christophe Bouin