Search code examples
bootstrap-4datetimepickertimepickerbootstrap-datetimepickertempus-dominus-datetimepicker

Tempusdominus Datetimepicker deformed or not showing as compared to Bootstrap examples


I would like my datetimepicker to be shown as the 5th datetimepicker in https://tempusdominus.github.io/bootstrap-4/Usage/#no-icon-input-field-only (No Icon (input field only)).

However, when using the CDNJS only, the output is a deformed version of what is shown in the examples. In an attempt to fix the problem, I included the source code found in the link below by attributing a local path. This makes the datetimepicker not showing up at all.

Source code: https://github.com/tempusdominus/bootstrap-4

Neither including the CDNJS only, the source code (local path) only nor both works.

I would like to be able to change the colours in the future so doing it with a source code would be more beneficial for me...

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-4/5.0.1/js/tempusdominus-bootstrap-4.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-4/5.0.1/css/tempusdominus-bootstrap-4.min.css" />

<link rel="stylesheet" type="text/css" href="lib/datetimepicker/tempusdominus-bootstrap-4.min.css" >
<script type="text/javascript" src="lib/datetimepicker/tempusdominus-bootstrap-4.min.js"></script>
 <div class="col-lg-12">
        <input type="text" class="form-control datetimepicker-input" id="datetimepicker5" data-toggle="datetimepicker" data-target="#datetimepicker5" placeholder="Data e Hora">
 </div>
<script>
        $(function () {
        $('#datetimepicker5').datetimepicker();
    });
</script>

Solution

  • (1) to get the dropdown to work as intended, i had to add

    • font-awesome.css
    • moment.js
    • tempusdominus-bootstrap-4.min.js
    • tempusdominus-bootstrap-4.css

    (2) to style the calendar which opens up, i added the following: .bootstrap-datetimepicker-widget table td{ color:red;} you can make relevant changes yourself

    complete working snippet below;

    .bootstrap-datetimepicker-widget table td {
      color: red;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css" />
    
    <script src="https://momentjs.com/downloads/moment.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
    
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-4/5.0.0-alpha14/js/tempusdominus-bootstrap-4.min.js"></script>
    <link rel="stylesheet" href="https://tempusdominus.github.io/bootstrap-4/theme/css/tempusdominus-bootstrap-4.css" />
    
    <div class="container">
      <div class="row">
        <div class="col-sm-6">
          <input type="text" class="form-control datetimepicker-input" id="datetimepicker5" data-toggle="datetimepicker" data-target="#datetimepicker5" />
        </div>
        <script type="text/javascript">
          $(function() {
            $('#datetimepicker5').datetimepicker();
          });
        </script>
      </div>
    </div>