0

I have an HTML page that uses Bootstrap3-dialog from github :

The page has a button, when you click on it a form with an input is displayed, I would like to add a datepicker to that input however it is generated dynamically and the click on the input does not show the datepicker.

From the code below you can see the the "console.log()" message is displayed when the input has focus so the datepicker should show normaly.

Can you help me figure out what is wrong with my code?

Thanks.

	$(function() {
	  $("body").on("focus", "#date", function() {
	    console.log("Supposed to show the datepicker"); //This is working so the datepicker should work too.
	    $('#date').datepicker();
	    $('#date').datepicker('show');
	  });
	  $("body").on("click", "#modal", function() {
	    BootstrapDialog.show({
	      message: '<div class="input-group"><span class="input-group-addon"><strong>Schedule date</strong></span><input value="" type="text" id="date" class="form-control">',
	      buttons: [{
	        icon: 'glyphicon glyphicon-send',
	        label: 'Save changes',
	        cssClass: 'btn-primary',
	        autospin: true,
	        action: function(dialogRef) {
	          dialogRef.enableButtons(false);
	          dialogRef.setClosable(false);
	          dialogRef.getModalBody().html('Dialog closes in 5 seconds.');
	          setTimeout(function() {
	            dialogRef.close();
	          }, 5000);
	        }
	      }, {
	        label: 'Close',
	        action: function(dialogRef) {
	          dialogRef.close();
	        }
	      }]
	    });
	  });
	});
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/nakupanda/bootstrap3-dialog/master/src/css/bootstrap-dialog.css">
<script type="text/javascript" charset="utf8" src="https://cdn.rawgit.com/nakupanda/bootstrap3-dialog/master/src/js/bootstrap-dialog.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script>
</script>

<body>
  <button type="button" id="modal" class="btn btn-primary">Show Modal</button>
</body>

3 Answers 3

1

The datepicker is hidden behing the overlay of modal. You need to set a higher z-index for it to appear.

.ui-datepicker {
  z-index: 2000; 
}
Sign up to request clarification or add additional context in comments.

3 Comments

That is right, good catch however why 2000 as value of the z-index? and is using 2000 will work on all browsers?
Also the console log message dispays twice on the input focus
@oussamakamal the modal overlay has z-index: 1050;, you might try using a lower value. The focus event is firing twice, but I'm not sure why exactly.
1

Initialize the datepicker when any modal is shown dynamically:

$(document).on('shown.bs.modal', function() {
    $('.datetimepicker').datetimepicker();
});

Comments

0

have you tired this:

  $("#date").on("click", function(){
        console.log("Supposed to show the datepicker");//This is working so the datepicker should work too.
        $('#date').datepicker();
        $('#date').datepicker('show');
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.