Search code examples
javascriptjquerytwitter-bootstrapjquery-uibootstrap-datetimepicker

Bootstrap datetimepicker installation/configuration


I'm having some issues with a basic configuration of the eonasdan bootstrap datetimepicker.

I created a fiddle using the code from their basic setup instructions to show my configuration. I see another Stackoverflow question on this topic that has another fiddle with older versions of the same plugins. The two fiddles look similar, but mine doesn't work.

<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>
        <script type="text/javascript">
            $(function () {
                $('#datetimepicker1').datetimepicker();
            });
        </script>
    </div>
</div>

Why doesn't the datetime picker in my fiddle work?


Solution

  • If you run your fiddle while inspecting the console you will see the following error:

    uncaught exception: bootstrap-datetimepicker requires Moment.js to be loaded first
    

    So it's simply a matter of the order in which the scripts are loaded. This is exactly the same fiddle, except bootstrap-datetimepicker.min.js is loaded last, and it works.

    Just take care of loading the resources in the right order, or use a dependency management tool to sort it out for you.