Allow exposing multiple variables through x-modelable
#3455
Replies: 2 comments 2 replies
-
How would you envision the API for it working? it might actually be already possible to use descructuring. like make both x-modelable and x-model an array |
Beta Was this translation helpful? Give feedback.
-
It would be handy to have this feature. I wonder whether it could be like Vue's multiple v-model binding syntax? https://vuejs.org/guide/components/v-model.html#multiple-v-model-bindings I'd imagine that Where as the Using the current <div x-data="{ number: 5, show: false }" >
<div
x-data="{ count: 0, open: true }" x-modelable="[count, open]" x-model:count="number" x-model:open="show">
...
</div>
...
</div> I think I prefer the array syntax for And for backwards compatibility, if Having everything together in the example seems strange without a component framework around it. So here's what an example would look like using Laravel's blade template, say using an autocomplete or combo box, where you need access to the selected item and the input value So this would be our autocomplete component template {{-- In blade `{{ $attributes }}` echos out any attributes passed into the component onto the element --}}
<div x-data="{ id: null, value: null}" x-modelable="['id', 'value']" {{ $attributes }}>
<input type="text" x-model="value" />
<ul>
<li x-on:click="id = 1">Option 1</li>
<li x-on:click="id = 2">Option 2</li>
</ul>
</div> And this is how we'd use it <div x-data="{ userId: null, name: null }">
<x-autocomplete x-model:id="userId" x-model:value="name" />
</div> |
Beta Was this translation helpful? Give feedback.
-
Hello!
x-modelable
is so useful, but there's been several times where I would like to expose multiple variables in my components, but have not been able to.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions