-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheForm.vue
75 lines (61 loc) · 1.71 KB
/
TheForm.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
73
74
75
<script setup lang="ts">
import { reactive, watchEffect } from 'vue'
import TheFormWaypoint from './TheFormWaypoint.vue';
import FieldWrapper from './common/FieldWrapper.vue';
import type { FormOrderItem } from '@/types.ts'
import { useOrderStore } from '@/stores/order.ts'
defineOptions({
name: 'TheForm'
})
const initialFormData = (): FormOrderItem => ({
customerName: '',
orderNumber: 0,
date: new Date(),
waypoints: []
})
const formData = reactive<FormOrderItem>(initialFormData())
const orderStore = useOrderStore()
function submit() {
orderStore.postOrder(formData)
}
watchEffect(() => {
if (orderStore.postingOrder.isSuccess) {
Object.assign(formData, initialFormData())
}
})
</script>
<template>
<form @submit.prevent="submit">
<div class="grid">
<FieldWrapper v-model="formData.customerName" label="Customer Name" id="customerName" required>
<input type="text" />
</FieldWrapper>
<FieldWrapper v-model="formData.orderNumber" label="Order Number" id="orderNumber" required>
<input type="number" />
</FieldWrapper>
<FieldWrapper v-model="formData.date" label="Order Date" id="date" required>
<input type="datetime-local" />
</FieldWrapper>
<div class="waypoints">
<TheFormWaypoint v-model="formData.waypoints" />
</div>
</div>
<button type="submit" :disabled="orderStore.postingOrder.isLoading">
{{ orderStore.postingOrder.isLoading ? 'Posting...' : 'Post Order' }}
</button>
</form>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 4rem;
row-gap: 1rem;
}
.waypoints {
grid-column: span 2;
}
button[type="submit"] {
margin-top: 2rem;
}
</style>