Skip to content

Instantly share code, notes, and snippets.

@lukaszmn
Last active May 25, 2021 17:26
Show Gist options
  • Save lukaszmn/0f293fc398f2bb1a9d9e6a77c003916c to your computer and use it in GitHub Desktop.
Save lukaszmn/0f293fc398f2bb1a9d9e6a77c003916c to your computer and use it in GitHub Desktop.
<html><body>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>
<div x-data="{ items: [], adding: false }" x-init="$refs.ok.disabled = true">
<template x-for="item in items" :key="item">
<div>
<span x-text="item"></span>
<button @click="items = items.filter(i => i !== item)">DEL</button>
</div>
</template>
<button @click="adding = true">ADD</button>
<div x-show.transition="adding" @click.away="adding = false">
<label for="name">Name:</label>
<input id="name" x-model="name" @keyup="$refs.ok.disabled = name.length === 0" />
<button @click="adding = false">CANCEL</button>
<button @click="adding = false; items.push(name); name = ''; $refs.ok.disabled = true" x-ref="ok">OK</button>
</div>
</div>
</body></html>
@uiartist
Copy link

Awesome, thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment