forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeForm.vue
More file actions
89 lines (79 loc) · 1.98 KB
/
NativeForm.vue
File metadata and controls
89 lines (79 loc) · 1.98 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<template>
<div class="q-pa-md">
<q-form @submit="onSubmit" class="q-gutter-md">
<div class="bg-grey-2 q-pa-sm rounded-borders">
Preferred genre:
<q-option-group
name="preferred_genre"
v-model="preferred"
:options="options"
color="primary"
inline
/>
</div>
<div class="bg-grey-2 q-pa-sm rounded-borders">
Accepted genres:
<q-option-group
name="accepted_genres"
v-model="accepted"
:options="options"
type="checkbox"
color="primary"
inline
/>
</div>
<div>
<q-btn label="Submit" type="submit" color="primary"/>
</div>
</q-form>
<q-card v-if="submitResult.length > 0" flat bordered class="q-mt-md bg-grey-2">
<q-card-section>Submitted form contains the following formData (key = value):</q-card-section>
<q-separator />
<q-card-section class="row q-gutter-sm items-center">
<div
v-for="(item, index) in submitResult"
:key="index"
class="q-px-sm q-py-xs bg-grey-8 text-white rounded-borders text-center text-no-wrap"
>{{ item.name }} = {{ item.value }}</div>
</q-card-section>
</q-card>
</div>
</template>
<script>
import { ref } from 'vue'
export default {
setup () {
const submitResult = ref([])
return {
preferred: ref('rock'),
accepted: ref([]),
submitResult,
options: [
{
label: 'Rock',
value: 'rock'
},
{
label: 'Funk',
value: 'funk'
},
{
label: 'Pop',
value: 'pop'
}
],
onSubmit (evt) {
const formData = new FormData(evt.target)
const data = []
for (const [ name, value ] of formData.entries()) {
data.push({
name,
value
})
}
submitResult.value = data
}
}
}
}
</script>