-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
96 lines (92 loc) · 3.26 KB
/
index.html
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
94
95
96
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Vue.JS Tutorial</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="app">
<div class="container">
<div class="col-md-6 col-md-offset-3">
<div class="lead-form">
<h1 class="text-center">Fill out this form</h1>
<hr>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" placeholder="Starting Zip" v-model='startingZip'>
<span class="city-span">{{ startingCity }}</span>
</div>
<div class="col-md-6">
<input type="text" class="form-control" placeholder="Ending Zip" v-model='endingZip'>
<span class="city-span">{{ endingCity }}</span>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="button" class="btn btn-primary btn-block" id="submit-form">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/lodash/4.17.4/lodash.min.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
startingZip: '',
startingCity: '',
endingZip: '',
endingCity: '',
},
watch: {
startingZip: function() {
// clear startingCity when startingZip input detected
this.startingCity = ''
if (this.startingZip.length == 5) {
// call API method to populate startingCity
this.lookupStartingZip()
}
},
endingZip: function() {
this.endingCity = ''
if (this.endingZip.length == 5) {
this.lookupEndingZip()
}
},
},
methods: {
lookupStartingZip: _.debounce(function() {
this.startingCity = 'Searching...'
axios.get('https://ziptasticapi.com/' + this.startingZip)
.then((response) => {
this.startingCity = response.data.city + ', '
+ response.data.state
})
.catch(function(error) {
this.startingCity = 'Invalid Zipcode'
})
}, 500),
lookupEndingZip: _.debounce(function() {
this.endingCity = 'Searching...'
axios.get('https://ziptasticapi.com/' + this.endingZip)
.then((response) => {
this.endingCity = response.data.city + ', '
+ response.data.state
})
.catch(function(error) {
this.endingCity = 'Invalid Zipcode'
})
}, 500),
}
})
</script>
</html>