/
Form.vue
72 lines (70 loc) · 1.86 KB
/
Form.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<template>
<div>
<form
class="flex items-stretch"
@submit.prevent="onSubmit"
autocomplete="off"
>
<input type="hidden" v-model="form.done" />
<label class="flex-1">
<span class="sr-only">New Todo</span>
<input
type="text"
name="todo"
ref="input"
class="appearance-none border rounded rounded-r-none w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
v-model="form.title"
autocomplete="off"
placeholder="Add new todo"
/>
</label>
<button
class="font-bold rounded rounded-l-none text-white px-4 hover:bg-green-800 bg-green-900 text-center no-underline block focus:shadow-outline focus:outline-none"
>
Add
</button>
</form>
<ContactPicker class="w-full" v-model="form.title" />
</div>
</template>
<script>
import ContactPicker from './Form/ContactPicker';
import uuid from 'uuid/v4';
export default {
components: {
ContactPicker,
},
data() {
// The shareTargetAPI creates a get Request that looks like this:
// /vue/?title={title}&text={text}&url={url}
const params = new URL(window.location).searchParams;
const title = [
...(params.get('title') ? [params.get('title')] : []),
...(params.get('text') ? [params.get('text')] : []),
...(params.get('url') ? [params.get('url')] : []),
];
return {
form: {
done: false,
title: title.join(' - '),
},
};
},
computed: {
isEmptyTitle() {
return this.form.title === '';
},
},
methods: {
onSubmit() {
if (!this.isEmptyTitle) {
this.$emit('submit', { ...this.form, id: uuid() });
this.$nextTick(() => {
this.form.title = '';
this.$refs.input.focus();
});
}
},
},
};
</script>