JackH
JackH

Reputation: 4745

How do I display Angular UI Bootstrap date picker on click?

I have an Angular app that uses Full Calendar. I have a Full Calendar custom button that when a user clicks, should open a Angular Bootstrap Datepicker. I'm currently toggling CSS visibility but for some reason, the date picker doesn't display (after clicking the button) unless I resize the window.

My template:

<div id="cal-go-to-date" ng-style="goToDate.style">
  <div uib-datepicker ng-model="goToDate.dt" class="well well-sm" datepicker-options="goToDate.options"></div>
</div>

My Angular controller:

$scope.uiConfig = {
  calendar: {
    // Other configuration
    header: {
      center: 'title'
    },
    customButtons: {
      goToDate: {
        text: 'go to date',
        click: function(event) {
          $scope.goToDate.style.visibility = 'visible';
        }
      }
    },
    // Other configuration
  }
};

$scope.goToDate = {
    dt: new Date(),
    options: {
      datepickerMode: 'month',
      minMode: 'month'
    },
    style: {
      'position': 'absolute',
      'top': '224px',
      'left': '76px',
      'min-height': '290px',
      'z-index': '99999',
      'visibility': 'hidden'
    }
  };

I am calling $scope.goToDate.style.visibility = 'visible'; but that doesn't work unless I resize the window. What can I do to toggle the visibility of the picker?

Upvotes: 3

Views: 857

Answers (2)

Stanislav Kvitash
Stanislav Kvitash

Reputation: 4622

Try wrapping the call with $applyAsync like:

$scope.$applyAsync(function(){ $scope.goToDate.style.visibility = 'visible'; });

since it looks like this happens outside of angularjs scope.

Upvotes: 1

Kartik Puri
Kartik Puri

Reputation: 467

If its the problem resizing try using this function

$scope.windowResize = function () {
            setTimeout("$(window).trigger('resize')",400);
         };

and then call this function on the click of that button . Hope it might help

Upvotes: 1

Related Questions