-1

I'm using HTML5 and adding an input with a type="date" for a date picker, but when I have Developer Tools open, every time I click in my input I get the following error displayed.

Uncaught DOMException: Failed to set the 'selectionEnd' property on 'HTMLInputElement': The input element's type ('date') does not support selection

Although it's not causing an issue to the user, ideally I don't want the error and was wondering if anyone has come across this and how to fix it.

This is my HTML:

<input id="startDate" class="form-control text-uppercase" type="date" />

Screenshot of my console.log:

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
murday1983
  • 3,806
  • 14
  • 54
  • 105
  • Hi! Could you share me more of your code? When I run your code in JSFiddle, I don't find any error messages. Please share me any javascript code which is "related" to this element – Manu G Jan 11 '21 at 15:34
  • selectionEnd property is not available for Date type, check the [this](https://html.spec.whatwg.org/multipage/input.html#do-not-apply) – Burham B. Soliman Jan 11 '21 at 15:44

1 Answers1

3

There's an answer to a related question here.

Essentially, Chrome is not currently supporting selection for inputs except the text, search, tel, url, and password types. You are triggering selectionEnd by clicking into the input; there's nothing wrong with your code.

The current suggested workaround is to set your input's type to text and use the pattern attribute to ensure valid input although that will not allow you to use the browser-provided date picker if one exists.

D M
  • 5,769
  • 4
  • 12
  • 27