I try to change the disabled days after the datetimepicker is initialised.
I do this with an ajax call but I tried to simplify the code.
I tried $('#datetimepicker').data("DateTimePicker").FUNCTION()
for the FUNCTION
I tried .disableddates
, .setDisabledDates
.
The first one erased the formerly declared disabled dates but did not add new ones.
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker-standalone.css" >
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js" ></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js" type="text/javascript" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/nl.js"></script>
<script src="/Scripts/bootstrap-datetimepicker.min.js" ></script>
</head>
<body>
<div class="container">
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
<div class="row">
<button class="btn button-default" onclick="ChangeDate()" >Change disabled days</button>
</div>
</div>
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker({
locale:"nl",
defaultDate: "2017-06-25",
disabledDates: ['2017-06-26','2017-06-27','2017-06-28'],
debug: false
});
});
function ChangeDate(){
alert('ChangeDate geklikt !');
$('#datetimepicker1').data("DateTimePicker").disabledDates(['2017-06-21','2017-06-22']);
alert('functie is uitgevoerd !');
}
</script>
</body>
</html>