1

i was working with ui.bootstrap.datePicker . i have the following code which disables specific dates using an array filled with dates to disable! now the problem is that it works online on plunker and when i use the same code on my local xampp server(v3.2.1), it does not disable the dates. any suggestions as to why it might be happening?

i will attach the plunker snippet too so that evryone knows it works fine online

siteDatePicker.js:

        var myApp= angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap', 'ui.bootstrap.dateparser', 'ui.bootstrap.datepicker']);



                     myApp.controller('DatepickerDemoCtrl', function($scope, $http) {



                    $scope.today = function() {
                        $scope.dt = new Date();
                      };
                      $scope.today();

                      $scope.clear = function() {
                        $scope.dt = null;
                      };

                      $scope.inlineOptions = {
                        customClass: getDayClass,
                        minDate: new Date(),
                        showWeeks: false
                      };

                      $scope.dateOptions = {
                          formatYear: 'yy',
                          maxDate: new Date(2020, 5, 22),
                          minDate: new Date(),
                          startingDay: 1
                        };

                        // Disable weekend selection
                        function disabledasda(data) {
                          var date = data.date,
                            mode = data.mode;
                          return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
                        }

                      $scope.toggleMin = function() {
                        $scope.inlineOptions.minDate = $scope.inlineOptions.minDate ? null : new Date();
                        $scope.dateOptions.minDate = $scope.inlineOptions.minDate;
                      };

                      $scope.toggleMin();

                      $scope.open1 = function() {
                        $scope.popup1.opened = true;
                      };


                      $scope.setDate = function(year, month, day) {
                        $scope.dt = new Date(year, month, day);
                      };

                      $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
                      $scope.format = $scope.formats[0];
                      $scope.altInputFormats = ['M!/d!/yyyy'];

                      $scope.popup1 = {
                        opened: false
                      };


                      var tomorrow = new Date();
                      tomorrow.setDate(tomorrow.getDate() + 1);
                      var afterTomorrow = new Date();
                      afterTomorrow.setDate(tomorrow.getDate() + 1);
                      $scope.events = [
                        {
                          date: tomorrow,
                          status: 'full'
                        },
                        {
                          date: afterTomorrow,
                          status: 'partially'
                        }
                      ];
                      $scope.disabled = function(date, mode){

                        var holidays = [
                          new Date(2016,2,14),
                          new Date(2016,2,15),
                          new Date(2016,2,16),
                        ]

                        var isHoliday = false;
                        for(var i = 0; i < holidays.length ; i++) {
                          if(areDatesEqual(holidays[i], date)){
                            isHoliday = true;
                          }
                        }

                        return ( mode === 'day' && isHoliday );
                      };

                      function areDatesEqual(date1, date2) {

                        return date1.getDate() == date2.getDate() &&
                               date1.getMonth() == date2.getMonth() &&
                               date1.getFullYear() == date2.getFullYear();

                      }

                      function getDayClass(data) {
                        var date = data.date,
                          mode = data.mode;
                        if (mode === 'day') {
                          var dayToCheck = new Date(date).setHours(0,0,0,0);

                          for (var i = 0; i < $scope.events.length; i++) {
                            var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);

                            if (dayToCheck === currentDay) {
                              return $scope.events[i].status;
                            }
                          }
                        }

                        return '';
                      }



                     });

siteDatePicker.html:

            <head>

              <title>SiteDatePicker</title>
              <meta charset="UTF-8">
              <meta name="viewport" content="width=device-width, initial-scale=1">
              <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
                  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
                <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script>
                <script src="./ui-bootstrap-tpls-1.2.1.min.js"></script>
              <script src="./siteDatePicker.js"></script>






            </head>


               <body ng-app="ui.bootstrap.demo" >
                <style>
                  .full button span {
                    background-color: limegreen;
                    border-radius: 32px;
                    color: black;
                  }
                  .partially button span {
                    background-color: orange;
                    border-radius: 32px;
                    color: black;
                  }
                </style>
                <div ng-controller="DatepickerDemoCtrl">
                  <pre>Selected date is: <em>{{dt | date:'fullDate' }}</em></pre>

                  <h4>Popup</h4>
                  <div class="row">
                    <div class="col-md-6">
                      <p class="input-group">
                        <input type="text" class="form-control"  uib-datepicker-popup="{{format}}" ng-model="dt" is-open="popup1.opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" alt-input-formats="altInputFormats" date-disabled="disabled(date, mode)" />
                        <span class="input-group-btn">
                          <button type="button" class="btn btn-default" ng-click="open1()"><i class="glyphicon glyphicon-calendar"></i></button>
                        </span>
                      </p>
                    </div>
                  </div>
                </div>
              </body>
            </html>

var app = angular.module('plunker', ['ui.bootstrap']);

app.controller('MainCtrl', function($scope,$q) {
  $scope.name = 'World';
  $scope.values = {
    date1: new Date()
  };

  var dateDisableDeferred =  $q.defer();
  $scope.dateDisablePromise = dateDisableDeferred.promise;
  
  var currentDay = new Date().getDay();
  var disableModeIsLessThan = true;
  
  $scope.toggleDisableMode = function() {
    dateDisableDeferred.notify(new Date().getTime());
    disableModeIsLessThan = !disableModeIsLessThan;
  };
  
  
  $scope.disabled = function(date, mode){

            var holidays = [
              new Date(2016,2,14),
              new Date(2016,2,15),
              new Date(2016,2,16),
            ]

            var isHoliday = false;
            for(var i = 0; i < holidays.length ; i++) {
              if(areDatesEqual(holidays[i], date)){
                isHoliday = true;
              }
            }

            return ( mode === 'day' && isHoliday );
          };

          function areDatesEqual(date1, date2) {

            return date1.getDate() == date2.getDate() &&
                   date1.getMonth() == date2.getMonth() &&
                   date1.getFullYear() == date2.getFullYear();

          }



});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="style.css" />
    <script data-require="[email protected]" src="https://code.angularjs.org/1.2.25/angular.js" data-semver="1.2.25"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <div class="container padTop">
      <p>Hello {{name}}!</p>

    <div>
      <div style="display:inline-block; min-height:290px;">
          <datepicker 
              ng-model="values.date1" 
              min-date="minDate" 
              show-weeks="true" 
             date-disabled="disabled(date, mode)"
              class="well well-sm"></datepicker>
      </div>
    </div>
  
   

    </div>
    
    
  </body>

</html>

1 Answer 1

1

Since i don't have enough points for comment. there fore i am writing comment as ans.

Clyde just check whether this two file are loading properly or not.

          <script src="./ui-bootstrap-tpls-1.2.1.min.js"></script>
          <script src="./siteDatePicker.js"></script>

Press F12 and network tab, see whether they are loaded or not.

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

1 Comment

yes done! the problem was with the loading of ui-bootstrap-tpls! i linked it now with: <script src="cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.1.2/…> .it wokrs fine now! thank you Avesh Naik!

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.