Datepicker not opening twice in angular-ui version 0.11.0

前端 未结 11 1443
一向
一向 2020-12-28 12:43

I am trying to have 2 datepickers and I am using Angular UI version 0.11.0.

My HTML code


     

        
相关标签:
11条回答
  • 2020-12-28 13:13

    I solved this problem by adding changing is-open from "opened" to "$parent.opened" Like this.

    seanControllers.controller('TracksController', ['$scope',
      function($scope) {
        $scope.openCalendar = function($event) {
          $event.preventDefault();
          $event.stopPropagation();
    
          $scope.opened = true;
        };
      }
    ]);
    <form>
      <label>Eindtijd</label>
      <div class="input-group">
        <input type="text" class="form-control" datetime-picker="dd-MM-yyyy HH:mm" ng-model="track.eindtijd" is-open="$parent.opened" />
        <span class="input-group-btn">
    	<button class="btn btn-default" type="button" ng-click="openCalendar($event)"><i class="glyphicon glyphicon-calendar"></i></button>
        </span>
      </div>
    </form>

    0 讨论(0)
  • 2020-12-28 13:13

    Same problem but the above solutions did not work for me, turns out I wasnt including this file: ui-bootstrap-tpls-0.14.2.js.

    Point is to make sure you are including all the files mentioned in the example documentation

    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.2.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
    

    Good Luck!

    0 讨论(0)
  • 2020-12-28 13:15

    Just isolate your dataPicker state variables.

    $scope.dataPickerStates = {
      open1:false,
      open2:false
    }
    

    then change your html to

    <input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="cdate.customStartDate" is-open="dataPickerStates.open1"  max-date="maxDate" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" class="input-md" />
    

    and finally your state changer method

    $scope.open = function($event, opened) {
      $event.preventDefault();
      $event.stopPropagation();
      $scope.datePickerStates[opened] = true;
    };
    

    that's it.

    0 讨论(0)
  • 2020-12-28 13:16

    I solved the problem like this :

    In the html file:

    <input is-open="opened"
           type="text" class="form-control" datepicker-popup="{{format}}" 
           ng-model="md" />
    

    and in the Javascript file, i just added a timeout to 'notify' that it's closed in order to be able to open it again :

    $scope.open = function($event) {
            $event.preventDefault();
            $event.stopPropagation();
            $scope.opened = true;
            setTimeout(function() {
                $scope.opened = false;
            }, 10);              
        };
    
    0 讨论(0)
  • 2020-12-28 13:16

    After looking at so many answers. What worked for me is something like below:

    $scope.datePicker = {
      date_opened:false
    }
    $scope.open_from = function($event) {
      $event.preventDefault();
      $event.stopPropagation();
      $scope.datePicker.date_opened = true;
    };
    

    HTML Template:

    <div class="input-group">
        <input name="date_obj_from" type="text" class="form-control" uib-
        datepicker-popup="dd-MMMM-yyyy" ng-model="date_obj_from" is-
        open="datePicker.date_opened" datepicker-options="dateOptions" 
        ng-required="true" close-text="Close" />
        <span class="input-group-btn">
           <button type="button" class="btn btn-default" ng-
        click="open_from($event)">
        <i class="glyphicon glyphicon-calendar"></i>
           </button>
        </span>
    </div>
    

    We do not have to involve $timeout fixing this issue. I mean why if someone does not need it. I fixed this issue by changing my attribue is-open="date_opened" to is-open="datePicker.date_opened". Always a best practice initializing key to you object.

    0 讨论(0)
提交回复
热议问题