It's impossible to use placeholder on date fields but I really need it.
I want two date inputs with texts "From" and "To" on each one as placeholders.
It's impossible to use placeholder on date fields but I really need it.
I want two date inputs with texts "From" and "To" on each one as placeholders.
The HTML5 date input field actually does not support the attribute for placeholder. It will always be ignored by the browser, at least as per the current spec.
As noted here
The
input[type="date"]
DOMElement only takes the following value:YYYY-MM-DD
, any other format or text with be skipped.Live Demo
HTML
Pure JavaScript
Performance review
In this exact case, with 2
input
elements, Pure JavaScript is ~40% ± 10% faster.With 32
input
elements, the difference remains the same (~43% ± 10% faster for Pure JS).use this input attribute events
I'm using this css method in order to simulate placeholder on the input date.
The only thing that need js is to setAttribute of the value, if using React, it works out of the box.
I'm using the following CSS only trick:
Ok, so this is what I have done:
This is to remove the placeholder when a value is given.
On focus or if .hasValue, remove the placeholder and its margin.