0

I use bootstrap ui library in Angular JS. Here there is Datepicket element. How I can show datepicker in two inputs? Link to library

I tried:

<input type="text" datepicker-popup="{{format}}">
<input type="text" datepicker-popup="{{format}}">

But this way opens inputs together

1
  • what are you using to actually open the datepicker? Is there a button and the ng-click sets a variable like the example in the documentation? Commented Apr 28, 2015 at 17:35

3 Answers 3

1

You need to provide minimum required attributes and without using ng-model how do you retrieve the date from the datepicker.

try using like this :

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

add this script in your controller :

$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();

$scope.opened = true;

};

working plunker for date picker

Sign up to request clarification or add additional context in comments.

4 Comments

@Hamed have a look at the working plunker [plnkr.co/edit/uXjl0mmml0dWYhcMxYMd?p=preview]
Look please, it opens two input together plnkr.co/edit/lvXJVhhp9Utg2DhInuVF?p=preview
Also how I can add own class to pop-up calendar?
you can not add a class to the pop up using datepickerconfig or something else. You better keep the datepicker within a container with a class name and write styles.
0

While ritesh's answer might correct it, the explanation isn't clear.

The reason you are having both open at the same time is because of this: is-open="opened".

The is-open is used to open the specified datepicker when this scope value is true. You mapped both datepickers to the same value. So when you call open($event) and set $scope.opened = true, it opens both.

What you really want to do is have a different function you call that sets the correct variable. So change the HTML to:

<input type="text" ng-click="open($event)" class="form-control" datepicker-popup="{{format}}" ng-model="dtModel" is-open="opened" />
<input type="text" ng-click="open2($event)" class="form-control" datepicker-popup="{{format}}" ng-model="dtModel2" is-open="opened2" />

And then add the function to your controller:

$scope.open2 = function($event) {
    $event.preventDefault();
    $event.stopPropagation();

    $scope.opened2 = true;
  };

See Plunkr

Comments

0

I looked into your plunker,it was opening two datepickers at once because $event was passed as opened for both input texts.

Change your input text to this

<input type="text" ng-click="open($event)" class="form-control" datepicker-popup="{{format}}" ng-model="dtModel" is-open="opened" />
 <input type="text" ng-click="open($event)" class="form-control" datepicker-popup="{{format}}" ng-model="dtModel2" is-open="opened2" />

Here is the working plunker

http://plnkr.co/edit/pCjeXpey3BYgKGBCffAp?p=preview

1 Comment

Thanks, never worked on ionic framework, but i guess it should work. Since, the bootstrap library is going to be same.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.