-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
use and x-for item with x-model #144
Comments
This is because you pass item by value, you need model witch passes by reference. <div x-data="{models:[{name:''}, {name: ''}]}">
<template x-for="model in models">
<input type="text" x-model="model.name">
</template>
<button @click="alert(JSON.stringify(models))">Show</button>
</div> |
@rzenkov But that same code will work in vue. just replace the x- with the v- and you will see |
Yes, but You get to keep your DOM, and sprinkle in behavior as you see fit. |
I haven't really wrapped my head around this, does anyone know if this is possible given the current approach (even if we made minor adjustments to the codebase?) I guess without diving in myself, I'm hoping someone can do the homework and explain why or why not this is possible, and what it would take. Thanks! |
@calebporzio ^ this patch should solve the issue. I added a bit of context in the PR description. Codepen: https://codepen.io/SimoTod/pen/MWYMyGP Are you okay with me sending another couple of PRs in the next few days to make it consistent with VueJS? I would add support for looping on object properties (like https://vuejs.org/v2/guide/list.html#v-for-with-an-Object) and for |
Hey guys, is there anything left to say on this issue? I don't believe the original post is necessarily a bug / problem with Alpine, since a scalar value is being used for the This can be worked around by using the array index instead: <template x-for="(item, index) in items">
<input x-model="items[index]" />
</template> (or see CodePen here: https://codepen.io/ryangjchandler/pen/vYGBgKy) |
Hey guys, I'm going to close this issue now. Please see my comment above about how it can work with arrays at the moment. If you think this is something that Alpine should definitely handle, please open a new Discussion which is where we try to keep all of our feature requests now. Cheers! 🙂 |
Hi,
Currently it's not possible to bind an
item
of an array using x-modelThis will not work
When i type in the input the
item
value doesn't changeEdit: The same thing works in vue
The text was updated successfully, but these errors were encountered: