Cristiano Magro
10 days ago 0adb44f6a15591ed98fa92ddae6fccf6ffd52373
commit | author | age
a19e6e 1 <template>
326c8c 2   <form @submit.prevent="submitForm">
a19e6e 3     <div class="form-control">
CM 4       <label for="user-name">Your Name</label>
326c8c 5       <input id="user-name" name="user-name" type="text" v-model="userName" />
a19e6e 6     </div>
CM 7     <div class="form-control">
8       <label for="age">Your Age (Years)</label>
9f2039 9       <input id="age" name="age" type="number" v-model="userAge" ref="inputAge" />
a19e6e 10     </div>
CM 11     <div class="form-control">
12       <label for="referrer">How did you hear about us?</label>
9f2039 13       <select id="referrer" name="referrer" v-model="referrer">
a19e6e 14         <option value="google">Google</option>
CM 15         <option value="wom">Word of mouth</option>
16         <option value="newspaper">Newspaper</option>
17       </select>
18     </div>
19     <div class="form-control">
20       <h2>What are you interested in?</h2>
21       <div>
0adb44 22         <input id="interest-news" name="interest" type="checkbox" value="news" v-model="interest" />
a19e6e 23         <label for="interest-news">News</label>
CM 24       </div>
25       <div>
0adb44 26         <input id="interest-tutorials" name="interest" type="checkbox" value="tutorials" v-model="interest" />
a19e6e 27         <label for="interest-tutorials">Tutorials</label>
CM 28       </div>
29       <div>
0adb44 30         <input id="interest-nothing" name="interest" type="checkbox" value="nothing" v-model="interest" />
a19e6e 31         <label for="interest-nothing">Nothing</label>
CM 32       </div>
33     </div>
34     <div class="form-control">
35       <h2>How do you learn?</h2>
36       <div>
0adb44 37         <input id="how-video" name="how" type="radio" value="video" v-model="how" />
a19e6e 38         <label for="how-video">Video Courses</label>
CM 39       </div>
40       <div>
0adb44 41         <input id="how-blogs" name="how" type="radio" value="blogs" v-model="how" />
a19e6e 42         <label for="how-blogs">Blogs</label>
CM 43       </div>
44       <div>
0adb44 45         <input id="how-other" name="how" type="radio" value="other" v-model="how" />
a19e6e 46         <label for="how-other">Other</label>
CM 47       </div>
0adb44 48     </div>
CM 49     <div class="form-control">
50       <input type="checkbox" id="confirm-terms" name="confirm-terms" v-model="confirm">
51       <label for="confirm-terms">Agree to terms of use?</label>
a19e6e 52     </div>
CM 53     <div>
54       <button>Save Data</button>
55     </div>
56   </form>
57 </template>
58
326c8c 59 <script>
CM 60 export default {
61   data() {
62     return {
63       userName: '',
79dfa2 64       userAge: null,
9f2039 65       referrer: 'wom',
0adb44 66       interest: [],
CM 67       how: null,
68       confirm: false,
326c8c 69     }
CM 70   },
71   methods: {
72     submitForm() {
79dfa2 73       console.log('Username: ' + this.userName);
326c8c 74       this.userName = '';
9f2039 75       console.log('User age: ');
CM 76       console.log(this.userAge); //number
77       console.log(this.$refs.inputAge.value);  //string
78       console.log(18);
0adb44 79       this.userAge = null;
9f2039 80
CM 81       console.log('referrer: ' + this.referrer);
82       this.referrer = 'wom';
79dfa2 83
0adb44 84       console.log('Checkbox: ');
CM 85       console.log(this.interest);
86       console.log('Radio buttons: ');
87       console.log(this.how);
88       this.interest = [];
89       this.how = null;
90
91       console.log('Confirm');
92       console.log(this.confirm);
93       this.confirm = false;
79dfa2 94     }
326c8c 95   }
CM 96
97 }
98 </script>
99
a19e6e 100 <style scoped>
CM 101 form {
102   margin: 2rem auto;
103   max-width: 40rem;
104   border-radius: 12px;
105   box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
106   padding: 2rem;
107   background-color: #ffffff;
108 }
109
110 .form-control {
111   margin: 0.5rem 0;
112 }
113
114 label {
115   font-weight: bold;
116 }
117
118 h2 {
119   font-size: 1rem;
120   margin: 0.5rem 0;
121 }
122
123 input,
124 select {
125   display: block;
126   width: 100%;
127   font: inherit;
128   margin-top: 0.5rem;
129 }
130
131 select {
132   width: auto;
133 }
134
135 input[type='checkbox'],
136 input[type='radio'] {
137   display: inline-block;
138   width: auto;
139   margin-right: 1rem;
140 }
141
326c8c 142 input[type='checkbox']+label,
CM 143 input[type='radio']+label {
a19e6e 144   font-weight: normal;
CM 145 }
146
147 button {
148   font: inherit;
149   border: 1px solid #0076bb;
150   background-color: #0076bb;
151   color: white;
152   cursor: pointer;
153   padding: 0.75rem 2rem;
154   border-radius: 30px;
155 }
156
157 button:hover,
158 button:active {
159   border-color: #002350;
160   background-color: #002350;
161 }
162 </style>