This is a JSP.
I’m using Bootstrap5 and this is my code :
<form action="" method="GET" class="row g-1 mb-3 ">
<div class="col-lg-2 col-md-4 col-6 mb-2">
<input type="date" class="form-control" name="startDate" style="font-size:.9rem">
</div>
<div class="col-lg-2 col-md-4 col-6 mb-2">
<input type="date" class="form-control" name="endDate" style="font-size:.9rem">
</div>
</div>
the view on Desktop :
the view on Mobile
this is how I import bootstrap :
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
//code
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" ></script>
I have read this answer :
Date field default text "DD-MM-YYYY" not showing on mobile devices but showing on Desktop
but I didn’t find it practical.
Remarque : When I test the mobile view with dev tools in the browser it works fine. the problem shows off only when Im on mobile.
2
Answers
For anyone facing this problem in the futur. Here's how I solved it using CSS and JS.
JS :
CSS :
in HTML just use the attribute placeholder.
I see. This is a known issue with the Bootstrap datepicker library. The default text for the date picker is not displayed on mobile devices if the format option is set to ‘dd/mm/yyyy’.
To fix this issue, you can use the todayHighlight option to set the default text to ‘Today’. The following code will fix the issue:
The todayHighlight option will highlight the current date in the date picker, and the default text will be set to ‘Today’. This will work on both desktop and mobile devices.
Solution with Javascript
This code uses the addEventListener() method to listen for the focus event on the input fields. When the input fields are focused, the code will set the value of the input fields to the current date. This will work on both desktop and mobile devices.