Not showing placeholder for input type=date field
It may not be appropriate... but it helped me.
<input placeholder="Date" class="textbox-n" type="text" onfocus="(this.type='date')" id="date">
Show placeholder text for input type date
use onfocus="(this.type='date')"
, example:
<input required="" type="text" class="form-control" placeholder="Date" onfocus="(this.type='date')"/>
How do I simulate placeholder functionality on input date field?
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" />
Placeholder for input type date (only when no value entered)
What you can do is to use change
event, in place of focus
. By using change
, the changes will take place only when input date would be valid :)
$( ".dateInput" ).change(function() {
if ( $(this).attr('value') != '' ) {
$(this).attr("placeholder", "").css('text-align', 'left');
console.log('no place');
} else {
$(this).attr("placeholder", "Date of Birth*").css('text-align', 'right');
console.log('place');
}
});
.loanInput {
width: 400px;
border: 3px solid #008e39;
font-family: 'Open Sans', sans-serif;
font-weight: 400;
font-size: 20px;
border-radius: 8px;
padding: 5px 10px;
margin-top: 20px;
}
input[type=date] {
text-align: right;
}
input[type="date"]:before {
color: #999;
content: attr(placeholder) !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="date" class="loanInput dateInput" required placeholder="Date of Birth*">
Related Topics
Disable Certain Dates from Html5 Datepicker
How to Disable an Input Dynamically With Angular 7
How to Allow Http Content Within an Iframe on a Https Site
How to Create an HTML Table With a Fixed/Frozen Left Column and a Scrollable Body
How to Align Content of a Div to the Bottom
Css When Inline-Block Elements Line-Break, Parent Wrapper Does Not Fit New Width
What Are the Default Margins For the HTML Heading Tags (≪H1≫, ≪H2≫, ≪H3≫, etc.)
How to Disable Viewport Zooming on Mobile Safari
Fixed Position Relative to Parent Container
Adding Arrows to the Right Using Bootstrap Accordion
How to Toggle Mat-Expansion-Panel With Button Click