0

I use angular moment picker. I wanted some dates disable dynamically from database.I use selectable Method but it works after the date selected. Anyone can help Me to disable date dynamically ?

view

<div class="col-md-2" >
    <div class="form-control" start-view="month" id="stringDate"  moment-picker="stringDate"   
     format="DD-MM-YYYY" locale="en" name="pickdate" ng-model="momentDate" 
    selectable="dateDisable(date,type)" required>
    <a class="pull-right" ng-if="stringDate"   ng-click="stringDate = ''">  &times; </a>
    <span ng-class="{'text-muted': stringDate}">
        {{stringDate || 'Select a date...' }}
    </span>
</div>

View Controller

$scope.dateDisable = function(date,type)
{
    var check = 0;
    for(var i=0;i<=$scope.leavedates.length;i++) {
        var disable = $scope.leavedates[i].Date_selected;
        check = type !== 'day' || date.format('DD-MM-YYYY') !== disable;
        if(!check)  {
            return false;
        }

    }
};
$scope.leavedates =[];
$scope.getDatesSelect_asleave = function()
{
    $http.post('url').success(function(response) {
    $scope.leavedates =response;


    });
}; 

1 Answer 1

0

You need to use the selectable method to allow selection of dates from database or as in example you can see that Sunday is not selectable.

You will have list of dates obtained from database which are either selectables or not then you can create similar function and return true or false based on selection.

There is a plunkr link on page itself if you want to try your function then create a json object that you get from your database and place your check in selectable method to see if it suits your need.

Sign up to request clarification or add additional context in comments.

4 Comments

The picker run before getting date from database. So the dates can't disabled.
This is a method so should be able to call it on picker object after dates are obtained.
$scope.leavedates is the array variable contains set of dates to be disable. After getting values in the array, How will i call the selctable method / and How the parameters will be pass.
When your promise is resolved or ajax call is finished then reinitialise the date picker like you did in the first place. I would recommend only initiate it after ajax call or promise resolved.

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.