Remove placeholder from date type input in chrome
28,373
Solution 1
You can hide the format placeholder with the following style rule:
<style>
::-webkit-datetime-edit-year-field:not([aria-valuenow]),
::-webkit-datetime-edit-month-field:not([aria-valuenow]),
::-webkit-datetime-edit-day-field:not([aria-valuenow]) {
color: transparent;
}
</style>
<input type=date>
Solution 2
You could achieve a nice effect using onfocus
and onfocusout
, along with some CSS.
<input name="date" type="text" onfocus="(this.type='date')" onfocusout="(this.type='text')">
Author by
Elad Lachmi
Updated on August 07, 2022Comments
-
Elad Lachmi almost 2 years
I have the following input:
<input class="AccordionLeft" id="operationDate" name="OperationDate" type="date" value="">
This shows the date format as a default placeholder. I would like to remove this placeholder and just have an empty input field.
If I do this:
`$('#operationDate').val('@DateTime.Now.ToString("yyyy-MM-dd")');`
I get today`s date as the placeholder, but if I use this:
$('#operationDate').val('');
I get the placeholder like
dd-mm-yyyy
. Can the placeholder be removed entirly? I have seen several posts about changing the date format, but have found none about removing the placeholder completley. -
Elad Lachmi almost 10 yearsThis has no effect at all, and also you are missing the actual selector and an opening brace.
-
int32_t almost 10 yearsOh, I'm sorry for the missing '{'. But it should work if you add {. jsfiddle.net/int32_t/DA3Nn
-
Elad Lachmi almost 10 yearsSorry, you
re right. I had something I tried overriding the placeholder. Can you add the missing
{` for completeness and I'll undo the downvote. Thank you. -
Elad Lachmi almost 10 yearsJust wanted to add that the selector for the slash separators is
::-webkit-datetime-edit-text:not([aria-valuenow])
-
Lukos over 8 yearsThat's a nice trick!
-
catalin87 about 8 yearsWorking perfect Very original solution :) gz
-
Hai Nguyen about 8 yearsIt should be
<input name="date" type="text" onfocus="(this.type='date')" onblur="if(!this.value)this.type='text'">
-
Loves2Develop over 7 yearsVery nice man, Like!
-
Luke C over 7 yearsUnfortunately, as of Dec 2016, this does not work on iOS. It renders the input field as text on load and does not re-render when the input type is dynamically altered with JS
-
Adambean about 6 yearsThis no longer works.