Martin Slezák
Martin Slezák

Reputation: 181

UI Bootstrap datepicker in ngDialog doesn't

I am trying to use the ui-bootstrap date picker in the ngDialog but I can only open it once. When I select the date, the picker is closed and I can't open it anymore. See plunker: http://plnkr.co/edit/obmNAWXAnCtNqa2YmioF

index.html:

<!DOCTYPE html>
<html ng-app="plunker">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.4.0/js/ngDialog.min.js"></script>
  <script src="ui-bootstrap-tpls-0.14.3.min.js" type="text/javascript"></script>
  <script src="app.js"></script>

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.4.0/css/ngDialog.min.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.4.0/css/ngDialog-theme-default.min.css" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" />
</head>

<body ng-controller="MainCtrl">
  <button ng-click="showCreateOrderPopup()">Create order</button>
</body>

</html>

app.js:

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

app.controller('MainCtrl', ['$scope', 'ngDialog', function($scope, ngDialog) {
  $scope.dateOptions = {
    formatYear: "yy",
    startingDay: 1,
    format: "shortDate"
  }

  $scope.createOrder = "";    
  $scope.showCreateOrderPopup = function() {
    ngDialog.openConfirm({
      template: "createOrderPopup.html",
      showClose: true,
      scope: $scope
    });
  }

  $scope.openedCreate = false;
  $scope.openDatePickerCreate = function($event) {
    $event.preventDefault();
    $event.stopPropagation();

    $scope.openedCreate = true;
  };
}]);

popup:

<form name="createOrderForm">
  <div class="row">
    <div class="form-group">
      <label for="createOrderStart">Start Time</label>
      <div>
        <div ng-class="{'has-error' : createOrderForm.createOrderStart.$error.required}">
          <div class="input-group">
            <input ng-model="createOrder.startTime" type="text" class="form-control" id="createOrderStart" name="createOrderStart" uib-datepicker-popup="shortDate" is-open="openedCreate" datepicker-options="dateOptions" current-text="Today" required clear-text="Clear"
            close-text="Close" ng-readonly="false" />
            <span class="input-group-btn">
            <button type="button" class="btn btn-primary" ng-click="openDatePickerCreate($event)">Cal</button>
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</form>

Strange thing is that when I add the datepicker dynamically (using ngRepeat) all works fine.

Any ideas how to make this work? Thanks in advance.

Upvotes: 3

Views: 520

Answers (1)

Shak Ham
Shak Ham

Reputation: 1269

I'm sorry, I just realized what you were talking about.

Change your code to the following:

$scope.status= {opened: false}
$scope.openDatePickerCreate = function ($event) {
    $scope.status.opened = true;
};

Also, change your html to the following:

is-open="status.opened"

All of this happens because of prototype inheritance. You may want to research on that.

Upvotes: 2

Related Questions