问题
I want a picker to be set to a month in the future by default. This works fine:
<script type="text/javascript">
$(function () {
$('#enddatepicker').datetimepicker({
defaultDate: moment().add(1, 'M').toDate(),
locale: 'de',
format: 'DD.MM.YYYY'
});
});
</script>
However, I also want the date to be not before tomorrow. So I try adding a minDate option:
<script type="text/javascript">
$(function () {
$('#enddatepicker').datetimepicker({
minDate: moment().add(1, 'd').toDate(),
defaultDate: moment().add(1, 'M').toDate(),
locale: 'de',
format: 'DD.MM.YYYY'
});
});
</script>
However, now the default date is set to minDate (that is, tomorrow). Can I set a default date independently from the minimum date?
回答1:
Looking at the code on GitHub (line 1674) if you set the option useCurrent to false, your default may not be overridden:
<script type="text/javascript">
$(function () {
$('#enddatepicker').datetimepicker({
useCurrent: false,
minDate: moment().add(1, 'd').toDate(),
defaultDate: moment().add(1, 'M').toDate(),
locale: 'de',
format: 'DD.MM.YYYY'
});
});
</script>
回答2:
I would raise an issue in github for this, as minDate
should not override defaultDate
. In the mean-time, all you can do is set the value explicitly:
$(function () {
$('#enddatepicker').datetimepicker({
minDate: moment().add(1, 'd').toDate(),
locale: 'de',
format: 'DD.MM.YYYY'
});
$('#enddatepicker').val(moment().add(1, 'M').format('DD.MM.YYYY'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/src/js/bootstrap-datetimepicker.js"></script>
<link href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="demo col-xs-6">
<input class="form-control" id="enddatepicker"/>
</div>
</div>
</div>
回答3:
Try with Start Date property, after checked my jquery i found that has not minDate parameter but startDate parameter to handle minDate.it will work for you.
startDate :new Date(),
skype @lokesh7676 to get more help
来源:https://stackoverflow.com/questions/31747344/defaultdate-and-mindate-with-bootstrap-datetimepicker