Open tianxu0836 opened 9 years ago
@tianxu0836 I am afraid that the the current version does not allow this. So I copied the code from http://eonasdan.github.io/bootstrap-datetimepicker/#linked-pickers and modified to use with my input fields:
<script type="text/javascript">
$(function () {
$('#period-from').on('dp.change', function (e) {
$('#period-to').data('DateTimePicker').minDate(e.date);
});
$('#period-to').on('dp.change', function (e) {
$('#period-from').data('DateTimePicker').maxDate(e.date);
});
});
</script>
Although it would be really cool if we could pass a model in datepicker options like datetimepicker-options="{ maxDate: vm.periodTo }"
.
How can I deal with the maxDate and minDate if use angularJS?
Hi, @xnyssxy
I use the following, this worked for me, using data-before-render
attribute.
In Html View:
<datetimepicker data-ng-model="data.date" data-before-render="beforeRender($view, $dates, $leftDate, $upDate, $rightDate)"></datetimepicker>
In AngularJS Controller
$scope.beforeRender = function ($view, $dates, $leftDate, $upDate, $rightDate) {
for(var i=0; i<$dates.length; i++ ) {
if( moment( $dates[i].utcDateValue ).isBefore(moment()) ){
$dates[i].selectable = false;
}
}
}
I hope it helps.
How do you set minDate and maxDate?