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
93 lines (84 loc) · 2.06 KB
/
NativeForm.vue
File metadata and controls
93 lines (84 loc) · 2.06 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
90
91
92
93
<template>
<div class="q-pa-md">
<q-form @submit="onSubmit" class="q-gutter-md">
<q-select
name="preferred_genre"
v-model="preferred"
:options="options"
color="primary"
filled
clearable
label="Preferred genre"
/>
<q-select
name="accepted_genres"
v-model="accepted"
multiple
:options="options"
color="primary"
filled
clearable
label="Accepted genres"
/>
<div>
<q-btn label="Submit" type="submit" color="primary"/>
</div>
</q-form>
<q-card v-if="submitEmpty" flat bordered class="q-mt-md bg-grey-2">
<q-card-section>
Submitted form contains empty formData.
</q-card-section>
</q-card>
<q-card v-else-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>
export default {
data () {
return {
preferred: 'rock',
accepted: [],
options: [
{
label: 'Rock',
value: 'rock'
},
{
label: 'Funk',
value: 'funk'
},
{
label: 'Pop',
value: 'pop'
}
],
submitEmpty: false,
submitResult: []
}
},
methods: {
onSubmit (evt) {
const formData = new FormData(evt.target)
const submitResult = []
for (const [ name, value ] of formData.entries()) {
submitResult.push({
name,
value
})
}
this.submitResult = submitResult
this.submitEmpty = submitResult.length === 0
}
}
}
</script>