Datepicker Bootstrap does not work

Asked

Viewed 12,385 times

1

I have a bootstrap Datepicker, but when I click on the button next to the text box, that calendar does not appear.

I thought it might be some link or script missing, but I always find only the datepicker code without the links it needs to make.

Follow the naughty one:

<!DOCTYPE html>
<html lang="utf-8">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
        <link rel="stylesheet" href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css" />
        <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
        <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/src/js/bootstrap-datetimepicker.js"></script>

    <title>PSA-Formações</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <style>
    body {

        background-color: #dcdcdc;
    }
    </style>
</head>

<body>

    <!-- content -->
    <div class="container">

        <div class="row">
            <div class="col-lg-12 text-center">
                <h1 style="
                    margin-top:100px;">Cadastro de Turmas</h1>
                <p> </p>
                <p class="lead"></p>
                <ul class="list-unstyled">
                    <form id="cadastro" name="cadastro" method="post" action="banco/updateT.php">

                       <!-- Olha ele aqui -->

                        <div class="container">
                        <div class="row">
                            <div class='col-sm-12'>
                                <div class="form-group">
                                    <div class='input-group date' id='datetimepicker1'>
                                        <label>Data:</label>
                                        <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> 
    <!-- /.container -->
    </div>

    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>

</body>
</html>
  • 1

    In function $('#datetimepicker1') no element with id datetimepicker1

  • I changed it, but it still doesn’t work :/

  • Another thing, I think I don’t need a datetime but only a date. It can transform?

1 answer

3


Debug by browser press F12 console guide to check if there is any Javascript error, because, I just generated a test and it worked, but at the end of this HTML has two Javascript that I have no test, note the minimum example running:

$(function() {
  $('#datetimepicker1').datetimepicker();
});
<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/src/js/bootstrap-datetimepicker.js"></script>

<div class="container">
  <div class="row">
    <div class="col-lg-12 text-center">
      <h1 style="
                    margin-top:100px;">Cadastro de Turmas</h1>
      <p> </p>
      <p class="lead"></p>
      <ul class="list-unstyled">
        <form id="cadastro" name="cadastro" method="post" action="banco/updateT.php">

          <!-- Olha ele aqui -->

          <div class="container">
            <div class="row">
              <div class='col-sm-12'>
                <div class="form-group">
                  <div class='input-group date' id='datetimepicker1'>
                    <label>Data:</label>
                    <input type='text' data-date-format="DD-MM-YYYY" 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>
          <!-- /.container -->

If you still want to format the date just go to the input and put a parameter (data-date-format="DD-MM-YYYY"), example:

<input type='text' data-date-format="DD-MM-YYYY" class="form-control" />
  • Ah, I copied your code and deleted my scripts from the bottom of the page and it worked! Let me ask an extra question. If I wanted to turn this datetimepicker into just datepicker?

  • 1

    @Marianaferreira is in the input configuration, edit the answer to better illustrate.

  • Boy, you are amazing!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.