-3

Explaination

I am successfully using an 'input type=date' as a datepicker in bootstrap 5.3, to select the date for data viewing.

The problem that i have is: i have to click on it to be visible.

For my situation, it has to be always visible, like a javascript calendar.

Question

How can this be achieved?

The code

  <form id="Create" method="post" asp-page-handler="CreateDate" >
  <input class="btn btn-secondary " type="date" name='newdate' onchange='this.form.submit()' >
2
  • 2
    You are using Bootstrap 4 and Bootstrap 5 at the same time? If not, correct your question tags and in any case, provide a minimal reproducible example that allows to reproduce the issue.
    – MrUpsidown
    Commented Jun 26 at 7:44
  • Bootstrap 5 doesn't have a datepicker. That's a regular HTML input.
    – gre_gor
    Commented yesterday

3 Answers 3

-1

As the built-in HTML input type="date" doesn't support always being visible. You can integrate the Bootstrap Datepicker and make it always visible.

 $(document).ready(function(){
            $('.datepicker-container').datepicker({
                format: 'yyyy-mm-dd',
                todayHighlight: true,
                autoclose: true
            }).on('changeDate', function(e) {
                $('#newdate').val(e.format('yyyy-mm-dd')).change();
            });
        });
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Datepicker Always Visible</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.3.0/css/bootstrap.min.css">
</head>
<body>
    <div class="container">
        <form id="Create" method="post" asp-page-handler="CreateDate">
            <div class="datepicker-container"></div>
            <input type="hidden" name="newdate" id="newdate" onchange="this.form.submit()">
        </form>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
</body>
</html>

2
  • 1
    This doesn't looks Bootstrap styled. And the calendar disappears after clicking.
    – gre_gor
    Commented Jun 27 at 16:47
  • 1
    That library is over 10 years old, requires Bootstrap 2.0.4+ and jQuery 1.7.1+ why would you use that in any new project?
    – MrUpsidown
    Commented Jun 27 at 22:30
-1

Use the below CDN links and the below function to call the date input

$('#datepkr').datepicker({
    uiLibrary: 'bootstrap5'
});
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://unpkg.com/[email protected]/js/gijgo.min.js" type="text/javascript"></script>
<link href="https://unpkg.com/[email protected]/css/gijgo.min.css" rel="stylesheet" type="text/css" />
<input id="datepkr" width="280" />

3
  • 1
    it has to be visible on page load, not after clicking on it.
    – Fillo
    Commented Jun 25 at 15:00
  • ohh okay.. see another answer. onload visible also onclick visible.
    – arxgoutam
    Commented Jun 26 at 4:17
  • Bootstrap 5.0.2? Why? Gijgo? Why?
    – MrUpsidown
    Commented Jun 26 at 7:47
-1

use all cdn

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<!-- Bootstrap JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Datepicker JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>

use this input date and this script

 <div class="container mt-5">
    <input type="text" id="datepicker" class="form-control">
</div>
<script>
    $(document).ready(function(){
        $('#datepicker').datepicker({
            autoclose: true
        });
        $('#datepicker').datepicker('show');
    });
</script>
2
  • 1
    Bootstrap 4.5.2? Why?
    – MrUpsidown
    Commented Jun 26 at 7:47
  • This just makes the popout calendar visible initially and doesn't make the calendar always visible.
    – gre_gor
    Commented Jun 28 at 11:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.