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

Dynamically assigning a value for x-target not working, but works if assigning it statically. #70

Closed
cocomansur opened this issue Apr 19, 2024 · 4 comments

Comments

@cocomansur
Copy link

cocomansur commented Apr 19, 2024

I've recently using Alpine-Ajax, and it's awesome, so thank you!

When dynamically setting the value for ":x-target" it does not work, it navigates me to the page that is supposed to be loaded into x-target. but if setting the "x-target" statically it does work. Maybe I'm doing something wrong?

settings :x-target dynamically (not working)

<template x-for="(note, index) in filenotes" :key="index">
<div>
<div :id="'note'+index"><p x-text="note.filenotes"></p></div>
<div><a :href="'filenotes-edit/'+info.profile.id" :x-target="'note'+index">edit</a></div>
</div>
</template>

settings x-target statically (working)

<template x-for="(note, index) in filenotes" :key="index">
<div>
<div :id="'note'+index"><p x-text="note.filenotes"></p></div>
<div><a :href="'filenotes-edit/'+info.profile.id" x-target="note0">edit</a></div>
</div>
</template>

@imacrayon
Copy link
Owner

Thanks for reporting this. I’m close to rolling out a fix, shooting for a release at the end of this week.

@imacrayon
Copy link
Owner

imacrayon commented Apr 26, 2024

Ah, you have a sneaky syntax error in the first code snippet, x-target is a directive so you have to drop the : prefix (just like x-text), this should work:

<template x-for="(note, index) in filenotes" :key="index">
<div>
<div :id="'note'+index"><p x-text="note.filenotes"></p></div>
<div><a :href="'filenotes-edit/'+info.profile.id" x-target="'note'+index">edit</a></div>
</div>
</template>

This won't fix everything yet, there's still an issue with dynamically evaluating x-target, but I'm working on that fix right now and the code above should work on the next release.

@imacrayon
Copy link
Owner

You can x-target:dynamic in v0.6.0 now:

<template x-for="(note, index) in filenotes" :key="index">
<div>
<div :id="'note'+index"><p x-text="note.filenotes"></p></div>
<div><a :href="'filenotes-edit/'+info.profile.id" x-target:dynamic="'note'+index">edit</a></div>
</div>
</template>

@cocomansur
Copy link
Author

Awesome! Thanks @imacrayon

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

No branches or pull requests

2 participants