1

I am unable to disable future dates.

Using angular-bootstrap-datetimepicker

<datetimepicker data-ng-model="user.join_date" data-datetimepicker-config="{ startView:'day', minView:'day' }"    />

Tried adding this.future = false; inside DateObject() of directive without any success...

EDIT

Found that I can use before-render and then make selectable=false; for future dates.

Trying to implement.

Thanks for any help!

0

2 Answers 2

1

Done it.

Used beforeRender function and disable future dates comparing utcDateValue with current date.

Here is the code:

$scope.beforeRender = function ($dates) {
    /* disable future dates */
    for(var i=0; i<$dates.length;i++) {
       if(new Date().getTime() < $dates[i].utcDateValue) {
          $dates[i].selectable = false;
       }
    }                
};

Added data-before-render="beforeRender($dates)" as well

<datetimepicker data-ng-model="user.join_date" data-datetimepicker-config="{ startView:'day', minView:'day' }" data-before-render="beforeRender($dates)" />
Sign up to request clarification or add additional context in comments.

Comments

0

Allow only future

I needed the exact opposite requirement that is slightly more complicated, to allow only future date you need to consider the argument $view

Javascript:

$scope.futureOnlyBeforeRender = function($view, $dates) {
// $view values: year, month, day, hour, minute
var currentDate = new Date();
// set the current date according to the view
switch($view){
    case 'year': currentDate.setYear(currentDate.getYear() - 1); break;
    case 'month': currentDate.setMonth(currentDate.getMonth() - 1); break;
    case 'day': currentDate.setDate(currentDate.getDate() - 1); break;
    case 'hour': currentDate.setHours(currentDate.getHours() - 1); break;
    case 'minute': currentDate.setMinutes(currentDate.getMinutes() - 1); break;
}
// apply ot the dates
$dates.filter(function (date) {
    return date.utcDateValue < currentDate.getTime();
}).forEach(function (date) {
    date.selectable = false;
})

};

HTML:

data-before-render="futureOnlyBeforeRender($view, $dates)"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.