forked from tushargugnani/learningVueJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14.dependent-dropdowns.html
81 lines (73 loc) · 3 KB
/
14.dependent-dropdowns.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body class="container">
<div class="row">
<div class="col-lg-12">
<div id="app">
<br />
<h2> Contact US </h2>
<form v-on:submit.prevent="formSubmit">
<div class="form-group">
<label for="refer">Countries</label>
<select name="refer" class="form-control" id="refre" v-model="form.country">
<option v-for="country in countries" v-bind:value=country.abbr>{{country.text}}</option>
</select>
</div>
<div class="form-group">
<label for="refer">States</label>
<select name="refer" class="form-control" id="refre" v-model="form.state">
<option v-for="state in states[form.country]" v-bind:value=state.abbr>{{state.text}}</option>
</select>
</div>
<div class="form-group">
<button class="btn btn-primary">Submit</button>
</div>
</form>
<div class="column">
<section class="section" id="results">
<div class="box alert alert-secondary">
<ul>
<!-- loop through all the `form` properties and show their values -->
<li v-for="(item, k) in form">
<strong>{{ k }}:</strong> {{ item }}
</li>
</ul>
</div>
</section>
</div>
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
form: {
country: null,
state: null
},
countries: [{abbr: 'IN', text: 'India'}, {abbr: 'US', text: 'USA'}],
states: {
IN : [{abbr: 'MP', text: 'Madhya Pradesh'}, {abbr: 'MH', text: 'Maharashtra'}],
US : [{abbr: 'NC', text: 'North Carolina'}, {abbr: 'FL', text: 'Florida'}]
}
},
watch: {
'form.country': function(){
this.form.state = null;
}
}
});
</script>
</html>