angular-bootstrap-datetimepicker-directive icon indicating copy to clipboard operation
angular-bootstrap-datetimepicker-directive copied to clipboard

maxDate and minDate

Open tianxu0836 opened this issue 10 years ago • 3 comments

How do you set minDate and maxDate?

tianxu0836 avatar May 07 '15 01:05 tianxu0836

@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 }".

rodrigosaling avatar Jun 18 '15 17:06 rodrigosaling

How can I deal with the maxDate and minDate if use angularJS?

xnyssxy avatar Mar 31 '16 11:03 xnyssxy

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.

diegoguevara avatar Jul 30 '16 14:07 diegoguevara