Skip to content

Instantly share code, notes, and snippets.

@TWithers
Created July 23, 2022 18:45
Show Gist options
  • Save TWithers/6224f339c5e4b77039b9bbec525d18ae to your computer and use it in GitHub Desktop.
Save TWithers/6224f339c5e4b77039b9bbec525d18ae to your computer and use it in GitHub Desktop.
<h1>List</h1>
<ul
x-data="{items: @entangle('items').defer, newItem:'', errors:{}}"
@validation.window="errors = $event.detail">
<template x-for="(item, index) in items">
<li x-bind:class="errors['item.'+index'] ? 'text-danger' : ''">
<span x-text="item"></span>
<i x-show="errors['item.'+index']"
x-text="errors['item.'+index] ? errors['item.'+index].join(' ') : ''"
>
</i>
</li>
</template>
</ul>
<input type="text" x-model="newItem" placeholder="Enter something">
<button type="button" @click="items.push(newItem)">Append</button>
<button type="button" @click="$wire.persistItems()">Persist</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment