Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
93
rated 0 times [  94] [ 1]  / answers: 1 / hits: 9632  / 3 Years ago, mon, april 26, 2021, 12:00:00

The default HTML input (code below) with type=date will display a date picker input.


However the date picker dialog only opens when you click on the calendar icon at the far right of the input.


If you click anywhere else in the input the dialog DOES NOT open.


How can you enable the input to open the date picker dialog when you click anywhere inside the input?


Note: I have already searched similar problems on Stack overflow for answers and on the internet but I did not get a proper solution.


<label for="session-date">Start date:</label>

<input type="date" id="session-date" name="session-date">

More From » html

 Answers
2

This should do it (without js!) when the field is clicked; when it is first focused it listens only for input, but you could workaround with js.


input#session-date {
display: inline-block;
position: relative;
}

input[type="date"]::-webkit-calendar-picker-indicator {
background: transparent;
bottom: 0;
color: transparent;
cursor: pointer;
height: auto;
left: 0;
position: absolute;
right: 0;
top: 0;
width: auto;
}

Note: You'll lose the icon using this method, but you could definitely add one:

Here's the demo on codepen


[#1427] Wednesday, April 21, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckaylab

Total Points: 311
Total Questions: 120
Total Answers: 93

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
;