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

inherit extraVars in x-for scope #357

Merged
merged 3 commits into from
Apr 18, 2020

Conversation

rhengles
Copy link
Contributor

@rhengles rhengles commented Apr 8, 2020

Fixes #356

This has worked for me, but I don't know if it's the proper solution.

Includes tests.

Thanks

@ryangjchandler
Copy link
Contributor

Seems like the proper solution. Thanks for submitting it!

@WL1981
Copy link

WL1981 commented Apr 10, 2020

Hope it will be merged soon

@rhengles rhengles force-pushed the x-for-access-outer-scope branch 3 times, most recently from 8e7717a to aafd796 Compare April 11, 2020 13:18
@rhengles
Copy link
Contributor Author

@calebporzio Rebased on #362 👍

@HugoDF
Copy link
Contributor

HugoDF commented Apr 13, 2020

@rhengles any idea why the tests are now failing?

@rhengles
Copy link
Contributor Author

@HugoDF It's something to do with the integration server, for some reason it couldn't run any of the tests.

From what I can see, it's not something related to the implementation. I'll try a force push and see if the tests run again...

@rhengles rhengles force-pushed the x-for-access-outer-scope branch from aafd796 to f439c35 Compare April 13, 2020 15:10
@HugoDF
Copy link
Contributor

HugoDF commented Apr 13, 2020

@rhengles cool!

@WL1981
Copy link

WL1981 commented Apr 16, 2020

There is a issue with the parent vars when I want to pass them to a x-on:click="Func(parentVar, subVar)" attribute / function.

To demonstrate the issue i've made a jsfiddle (using latest commit f439c35)

When I click on a checkbox the alert always shows the last subitem.name in the subitems object.

<div x-data="GetData()">

  <template x-for="item in Object.values(items)">
    <div>

        <div x-text="item.title"></div>
                <input type="checkbox" x-on:click="toggle(item.title. 'test' )" />

        <template x-for="subitem in Object.values(item.data.subitems)">
          <div>

            <label>
            
              <input type="checkbox" x-on:click="toggle(item.title,  subitem.name )" />
              <span x-text="subitem.name"></span>
            </label>

          </div>
        </template>


    </div>
  </template>
</div>

I hope I have described the problem clearly enough. If not then I would like to hear it so that it can be solved as soon as possible.

src/directives/for.js Outdated Show resolved Hide resolved
Thanks @SimoTod

Co-Authored-By: Simone Todaro <simo.todaro@gmail.com>
@rhengles
Copy link
Contributor Author

@WL1981 I will also add this test to ensure this doesn't happen again.

@calebporzio
Copy link
Collaborator

Thanks @rhengles !

@calebporzio calebporzio merged commit 2dc7607 into alpinejs:master Apr 18, 2020
@calebporzio
Copy link
Collaborator

Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested x-for: Cannot access outer loop variable from inside inner loop
6 participants