<template> <section class="forms content"> <h1 class="title is-4">Forms</h1> <hr /> <div class="columns"> <div class="column is-4"> <h4>Public lists</h4> <p>Select lists to add to the form.</p> <ul class="no"> <li v-for="l in lists" :key="l.id"> <b-checkbox v-model="checked" :native-value="l.uuid">{{ l.name }}</b-checkbox> </li> </ul> </div> <div class="column"> <h4>Form HTML</h4> <p> Use the following HTML to show a subscription form on an external webpage. </p> <p> The form should have the <code>email</code> field and one or more <code>l</code> (list UUID) fields. The <code>name</code> field is optional. </p> <pre><!-- eslint-disable max-len --><form method="post" action="http://localhost:9000/subscription/form" class="listmonk-form"> <div> <h3>Subscribe</h3> <p><input type="text" name="email" placeholder="E-mail" /></p> <p><input type="text" name="name" placeholder="Name (optional)" /></p> <template v-for="l in lists"><span v-if="l.uuid in selected" :key="l.id" :set="id = l.uuid.substr(0, 5)"> <p> <input id="{{ id }}" type="checkbox" name="l" value="{{ uuid }}" /> <label for="{{ id }}">{{ l.name }}</label> </p></span></template> <p><input type="submit" value="Subscribe" /></p> </div> </form></pre> </div> </div> </section> </template> <script> import Vue from 'vue'; export default Vue.extend({ name: 'ListForm', data() { return { checked: [], }; }, computed: { lists() { if (!this.$store.state.lists.results) { return []; } return this.$store.state.lists.results.filter((l) => l.type === 'public'); }, selected() { const sel = []; this.checked.forEach((uuid) => { sel[uuid] = true; }); return sel; }, }, mounted() { this.$api.getLists(); }, }); </script>