Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calendar not showing up in Bootstrap datetimepicker

I am implementing bootstrap datetimepicker with below code:

<div class="container">
    <div class="row">
        <div class="col-sm-6">
            <div class="form-group">
                <div class="input-group date" id="datetimepicker1">
                    <input type="text" class="form-control" />
                    <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>

I have included below scripts and styles: Files included

And my output is looking like below: Output on page

Order of including files is:

@Styles.Render("~/Content/css")
@Styles.Render("~/Content/Styles/PreLayout.css")

@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/moment")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/Scripts/JavaScripts/PreLayout.js")

When I click on calendar icon nothing happens. What mistake I am making in implementation?

EDIT:

Added fiddler: http://jsfiddle.net/1c1nr9sp/4/

like image 304
ATP Avatar asked Jul 24 '15 03:07

ATP


People also ask

Why my bootstrap Datepicker is not working?

Because you're defining the code in the head the body and its contents haven't been loaded yet; so the selector finds no elements to initialize datepicker. If you don't want to use document. ready functionality you could also move the script to the end of the body tag. Works perfectly fine now...

Does bootstrap 4 have a Datepicker?

Bootstrap date picker is a plugin that adds the function of selecting time without the necessity of using custom JavaScript code. This documentation may contain syntax introduced in the MDB 4.17. 0 and can be incompatible with previous versions. For old Date Picker documentation please follow the link.

Does bootstrap have a Datepicker?

As with bootstrap's own plugins, datepicker provides a data-api that can be used to instantiate datepickers without the need for custom javascript. For most datepickers, simply set data-provide="datepicker" on the element you want to initialize, and it will be intialized lazily, in true bootstrap fashion.

What is bootstrap DateTimePicker?

Bootstrap 5 DateTimepicker. DateTimepicker is a form that adds the function of selecting date and time without the necessity of using custom JavaScript code.


2 Answers

The cause of your issue is, you did not place the reference scripts in correct order.

See the documentation: http://eonasdan.github.io/bootstrap-datetimepicker/Installing/

$('#datetimepicker1').datetimepicker();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script src="http://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/src/js/bootstrap-datetimepicker.js"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>

<link href="http://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/a549aa8780dbda16f6cff545aeabc3d71073911e/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<div class="container">
    <div class="row">
        <div class='col-sm-6'>
            <div class="form-group">
                <div class='input-group date' id='datetimepicker1'>
                    <input type='text' class="form-control" />
                    <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
            </div>
        </div>
        
    </div>
</div>
like image 59
JGV Avatar answered Oct 03 '22 15:10

JGV


As far as the messed up spacing between the textbox and calendar icon, I was able to fix that by commenting out the line:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />

My project handles this for me instead. ASP.net/MVC I also changed the col-sm-6 to col-sm-12.

like image 38
JaymesG Avatar answered Oct 03 '22 14:10

JaymesG