Search code examples
angularjsangular-uiangular-ui-bootstrap

Angular-ui-bootstrap - Date Picker - How can I restrict access to the date-selector in popup?


At the moment, I can first select the year, then the month, and then, the date. However, I only need access to month and the year. I'm not sure how to disable the date-selector option.

Also, I would like to get rid of all the footer buttons (today, clear, etc) in the date-picker as well. How can I achieve this ?

I'm looking for something similar to '$scope.showweeks = false;'

Below is my Plunker example

Plunker- Month year picker

Please feel free to direct me to any documentations available. So far, I could only find

http://angular-ui.github.io/bootstrap/

Thanks


Solution

  • You can try to use datepicker for Bootstrap with jQuery wrapped by directive.

    See Plunker

    JS

    var app = angular.module('plunker', []);
    
    app.controller('MainCtrl', function($scope) {
      $scope.var1 = '07-2013';
    });
    
    
    app.directive('datetimez', function() {
        return {
            restrict: 'A',
            require : 'ngModel',
            link: function(scope, element, attrs, ngModelCtrl) {
              element.datetimepicker({
               format: "MM-yyyy",
               viewMode: "months", 
                minViewMode: "months",
                  pickTime: false,
              }).on('changeDate', function(e) {
                ngModelCtrl.$setViewValue(e.date);
                scope.$apply();
              });
            }
        };
    });
    

    HTML

       <div id="date" class="input-append" datetimez ng-model="var1">
          <input data-format="MM-yyyy" type="text" id="input1" name="input1"></input>
          <span class="add-on">
            <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
          </span>
        </div>
    

    enter image description here