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>