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.
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.
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.
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')">
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With