-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathReviewForm.js
52 lines (46 loc) · 1.15 KB
/
ReviewForm.js
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
app.component('review-form', {
template:
/*html*/
`
<form class="review-form" @submit.prevent="onSubmit">
<h3>Leave a review</h3>
<label for="name">Name:</label>
<input id="name" v-model="name">
<label for="review">Review:</label>
<textarea id="review" v-model="text"></textarea>
<label for="rating">Rating:</label>
<select id="rating" v-model.number="rating">
<option>5</option>
<option>4</option>
<option>3</option>
<option>2</option>
<option>1</option>
</select>
<input class="button" type="submit" value="Submit">
</form>
`,
data() {
return {
name: '',
text: '',
rating: null
}
},
methods: {
onSubmit() {
if (this.name === '' || this.text === '' || this.rating === null) {
alert('Review is incomplete. Please fill out every field.')
return
}
const review = {
name: this.name,
text: this.text,
rating: this.rating
}
this.$emit('review-submitted', review)
this.name = ''
this.text = ''
this.rating = null
}
}
})