Error With Bootstrap 3 Date/Time Picker

80,575

Solution 1

According to the examples, you need to include this to..

http://momentjs.com/

It has to be after bootstrap.js, but before the datetimepickerjs like this..

<script type="text/javascript" src="scripts/bootstrap.min.js"></script>
<script type="text/javascript" src="scripts/moment-2.4.0.js"></script>
<script type="text/javascript" src="scripts/bootstrap-datetimepicker.js"></script>

It shows it on the GitHub readme..

"Datetimepicker requires moment.js."

Solution 2

Simple solution

Once even I got the same error. I was able to fix that by including the content delivery network or content distribution network (CDN) link of the script file.

Try the code below:

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.js"></script>

Include the above code before adding-in the bootstrap-datetimepicker.js

Share:
80,575

Related videos on Youtube

user3167249
Author by

user3167249

Updated on November 16, 2020

Comments

  • user3167249
    user3167249 over 3 years

    I am using the date/time picker from Eonasden that you can find here. Date Time Picker

    I am using HTML from the example:

    <div class="container">
        <div class="col-md-10">
            <div class='well'>
                <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>
    

    It displays the icon fine, but not the calendar drop down. My head script is:

    <link href="view/dist/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="view/dist/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
    <link href="http://cdnjs.cloudflare.com/ajax/libs/jasny-bootstrap/3.0.1-p7/css/bootstrap.min.css" rel="stylesheet" >
    
    <script src="http://code.jquery.com/jquery.js"></script>
    <script src="view/dist/js/bootstrap.min.js"></script>
    <script src="view/dist/js/bootstrap-datetimepicker.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/jasny-bootstrap/3.0.1-p7/js/bootstrap.min.js"></script>
    
    $(function() {
    
      $( document ).ajaxStop( function() {
        $('#datetimepicker1').datetimepicker();
      });
    
    });
    

    I receive a console error of "Uncaught ReferenceError: moment is not defined" Does anyone have an idea on how to fix this? It seems to work fine on his sample page.

    • Aditya
      Aditya about 10 years
      Did you download moment.js and reference it from your code?
    • JosephK
      JosephK over 9 years
      You must also add the 'momentjs-rails' gem, and then modify your application.js file, to require it before the "bootstrap-datetimepicker" entry.
  • user3167249
    user3167249 about 10 years
    I did not see that in the GitHub build. Where did you find that? I did add it an still no luck though.
  • user3167249
    user3167249 about 10 years
    I do see that now. However that still did not fix the issue. I no longer get any errors in the console, but still no drop down.
  • user3167249
    user3167249 about 10 years
    Sorry I overlooked the order of the scripts. Works great now. Thanks