How to have at least two datepickers of ui-bootstrap on a single page?

前端 未结 7 1912
青春惊慌失措
青春惊慌失措 2020-12-04 14:12

I want to have several datepickers on a page. But with the default solution from UI-Bootstrap it is not possible, no one of datepickers may be opened. The conflict with each

相关标签:
7条回答
  • 2020-12-04 15:07

    Rather than using a different function you can use a different is-open attribute and then pass the attribute in through the ng-click function. You still need different models:

    <div>
            <div class="form-horizontal pull-left">
                <input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt1" is-open="opened1" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true"/>
                <button class="btn" ng-click="open($event,'opened1')"><span class="glyphicon glyphicon-calendar"></span></button>
            </div>
            <div class="form-horizontal pull-left">
                <input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt2" is-open="opened2" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" />
                <button class="btn" ng-click="open($event,'opened2')"><span class="glyphicon glyphicon-calendar"></span></button>
            </div>
            <button type="submit" class="btn btn-default">Submit</button>
        </div>
    

    And inside controller:

       $scope.open = function($event,opened) {
        $event.preventDefault();
        $event.stopPropagation();
    
        $scope[opened] = true;
      };
    
    0 讨论(0)
提交回复
热议问题