Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I simulate placeholder functionality on input date field?

Tags:

html

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.

like image 412
Shkarik Avatar asked Aug 09 '13 12:08

Shkarik


People also ask

How do you show placeholder in input type date in react?

type='date')" onblur="(this. type='text')" Warning: Expected `onFocus` listener to be a function, instead got a value of `string` type. Warning: Expected `onBlur` listener to be a function, instead got a value of `string` type.

How do you place placeholder inside input?

Use the ::placeholder pseudo-element to style your placeholder text in an <input> or <textarea> form element. Most modern browsers support this, but for older browsers, vendor prefixes will be required.


1 Answers

I'm using the following CSS only trick:

  input[type="date"]:before {      content: attr(placeholder) !important;      color: #aaa;      margin-right: 0.5em;    }    input[type="date"]:focus:before,    input[type="date"]:valid:before {      content: "";    }
<input type="date" placeholder="Choose a Date" />
like image 84
Roman Avatar answered Oct 04 '22 09:10

Roman