Kim Ocampo Octaviano
Kim Ocampo Octaviano

Reputation: 75

Bootstrap DatePicker inside Modal not working

I have this datepicker inside a modal but not working. I already tried some of the codes i saw in the forum, but none of them is working. Could this be a javascript problem? I am not sure what making it not to show the datepicker,anyone who can help me please thanks enter image description here

<script>
$(document).ready(function() {
    $('#datePicker')
        .datepicker({
            format: 'mm/dd/yyyy'
        })
        .on('changeDate', function(e) {
            // Revalidate the date field
            $('#eventForm').formValidation('revalidateField', 'date');
        });

    $('#eventForm').formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            name: {
                validators: {
                    notEmpty: {
                        message: 'The name is required'
                    }
                }
            },
            date: {
                validators: {
                    notEmpty: {
                        message: 'The date is required'
                    },
                    date: {
                        format: 'MM/DD/YYYY',
                        message: 'The date is not a valid'
                    }
                }
            }
        }
    });
});
</script>
<div class="form-group">
        <label class="col-xs-3 control-label">Date</label>
        <div class="col-xs-5 date">
            <div class="input-group input-append date" id="datePicker">
                <input type="text" class="awe-calendar" name="date" />
                <span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
            </div>
        </div>
    </div>

Upvotes: 5

Views: 37717

Answers (6)

muchtarsp
muchtarsp

Reputation: 237

I have similar issue and after several hour, i have found this simple but useful answer in css.

If you want to use jquery after you call the modal, you can do like this:

$('#infoModal').modal('show');
$('#infoModal').on('shown.bs.modal', function(e) {
    $('.bootstrap-datetimepicker-widget').css('z-index', 1500);
});

Thanks to Alfredo

Upvotes: 1

Nurkartiko
Nurkartiko

Reputation: 181

add this:

$('#datePicker')
    .datepicker({
        format: 'mm/dd/yyyy',
         beforeShow: function () {
              setTimeout(function () {
                  $('.ui-datepicker').css('z-index', 99999);
              }, 0);
          }
    })
    .on('changeDate', function(e) {
        // Revalidate the date field
        $('#eventForm').formValidation('revalidateField', 'date');
    });

Upvotes: 0

Ahmadreza Pourghodrat
Ahmadreza Pourghodrat

Reputation: 98

Change the id of the input tag to datepicker, it may work.

Upvotes: 0

Abhilash Thomas
Abhilash Thomas

Reputation: 863

I made a sample application for to show it. Its work fine

<!DOCTYPE html>
<html>
<head>
    <title>The Date</title>
    <meta charset="utf-8" /> 
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"> 
    <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> 
    <script>
        $(function () {
            $('#datetimepicker1').datepicker({
            });
        });
    </script>
</head>
<body>
    <div class="container">
        <div class="">&nbsp;</div>
        <!-- Button trigger modal -->
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
            Launch demo modal
        </button>
    </div>
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Pick your Date</h4>
                </div>
                <div class="modal-body">
                    <input id="datetimepicker1" type="text" class="form-control" />
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div> 
</body>
</html>

Upvotes: 1

Abhilash Thomas
Abhilash Thomas

Reputation: 863

The same issue i faced, the best method is please check the below code which i used to fix this issue. This will work wen you click any where in the body

Please add the just above of

div model-body

    <script>
      $(document).on("click", ".modal-body", function () {
       $("#datepicker").datepicker({
         dateFormat: 'yy-mm-dd'                                    
         });
          });  
    </script> 
 <div class="modal-body">

Upvotes: 2

RiesvGeffen
RiesvGeffen

Reputation: 1589

add z-index above 1051 in class datepicker

add something like this in page or css

<style>
  .datepicker{z-index:1151 !important;}
</style>

Upvotes: 8

Related Questions