Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would I use this inside ng-repeat? #155

Closed
Fossil01 opened this issue Oct 24, 2016 · 9 comments
Closed

How would I use this inside ng-repeat? #155

Fossil01 opened this issue Oct 24, 2016 · 9 comments

Comments

@Fossil01
Copy link

@Fossil01 Fossil01 commented Oct 24, 2016

When used inside ng-repeat (adding multiple users to a form) clicking on the calender icon the datepicker opens for each user.

@Gillardo
Copy link
Owner

@Gillardo Gillardo commented Oct 24, 2016

Cos you are using the same value for IsOpen.... You need to use a different variable for each one

@Fossil01
Copy link
Author

@Fossil01 Fossil01 commented Oct 24, 2016

How? I tried the following:

<input type="text" class="form-control"  datetime-picker="dd-MM-yyyy" ng-model="visitor.birthdate" is-open="picker[[$index]].open" enable-time="false"
 save-as="true" datepicker-options="picker[[$index]].datepickerOptions" close-on-date-selection="false" datepicker-append-to-body="false" />
<span class="input-group-btn">
    <button type="button" class="btn btn-default" ng-click="openCalendar($event, 'picker' + $index)"><i class="fa fa-calendar"></i></button>
</span>
    $scope.picker0 = {};

    $scope.openCalendar = function(e, picker) {
      console.log(picker);
      console.log($scope[picker]);
        $scope[picker].open = true;
    };

Two problems:
The picker won't open now.
I need to manually create a $scope.picker0 $scope.picker1 etc. for each possible repeat.

How can we create something more scalable? It does work when I remove [[$index]] from is-open and datepicker-options and just hardcore it as picker0 for this example.

@Gillardo
Copy link
Owner

@Gillardo Gillardo commented Oct 24, 2016

Why have you wrote picker[[$index]].datepickerOptions?? Shouldnt that bepicker[$index].datepickerOptions` ? (without the double [[ ]]). Just dont set the is-open property and it will use a local variable from inside the datepicker control....

@Gillardo
Copy link
Owner

@Gillardo Gillardo commented Oct 24, 2016

Also, are all your datepickers different?? If not, pass in the same object for each one... If they are, then you need to pass in a different object for each different one

@Fossil01
Copy link
Author

@Fossil01 Fossil01 commented Oct 24, 2016

No they are the same for this page.

picker[$index].datepickerOptions and picker[$index].isopen does not work either. The index is 0 in this case. When I write picker0.isopen and picker0.datepickerOptions it does work but that's not scalable.

@Gillardo
Copy link
Owner

@Gillardo Gillardo commented Oct 24, 2016

can you create a simple plunkr to replicate and i will have a look

@Fossil01
Copy link
Author

@Fossil01 Fossil01 commented Oct 25, 2016

Hah that works perfectly in the plnkr. Cheers!

@Fossil01 Fossil01 closed this Oct 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.