Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove placeholder from date type input in chrome [duplicate]

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.

like image 953
Elad Lachmi Avatar asked Jul 29 '14 15:07

Elad Lachmi


People also ask

How do I change the default placeholder date in input type?

The placeholder attribute does not work with the input type Date, so place any value as a placeholder in the input type Date. You can use the onfocus=”(this. type='date') inside the input filed.

How do I change the input date format?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.


2 Answers

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')">
like image 168
Jeroen Bellemans Avatar answered Oct 03 '22 13:10

Jeroen Bellemans


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>
like image 21
int32_t Avatar answered Oct 01 '22 13:10

int32_t