1 | <template>
|
2 | <form @submit.prevent="submit"
|
3 | v-form="patientForm"
|
4 | class="borderRadius25 marginRightAuto marginLeftAuto displayFlex
|
5 | bgWhisper">
|
6 |
|
7 | <div class="flex1 padding30">
|
8 |
|
9 |
|
10 | <div class="marginBottom30 widthTwelve">
|
11 |
|
12 | <div class="marginBottom10">
|
13 | <label for="name" class="colorMidGray fontSize14">
|
14 | Your name
|
15 | </label>
|
16 | </div>
|
17 |
|
18 | <input id="name"
|
19 | type="text"
|
20 | class="inputText widthTwelve"
|
21 | v-model="patientData.name"
|
22 | pattern="[A-Za-z\s'\-]+"
|
23 | minlength="3"
|
24 | required>
|
25 |
|
26 | <div v-if="patientForm.$wasSubmitted"
|
27 | class="marginTop12 widthTwelve colorRed fontSize14">
|
28 | <div v-if="patientForm.name.valueMissing">
|
29 | Name is required.
|
30 | </div>
|
31 | <div v-if="patientForm.name.tooShort">
|
32 | Please enter your first and last name.
|
33 | </div>
|
34 | <div v-if="patientForm.name.patternMismatch">
|
35 | Please use only letters, spaces, dashes, and apostrophes.
|
36 | </div>
|
37 | </div>
|
38 |
|
39 | </div>
|
40 |
|
41 |
|
42 | <div class="marginBottom30 widthTwelve">
|
43 |
|
44 | <div class="marginBottom10">
|
45 | <label for="email" class="colorMidGray fontSize14">
|
46 | Your sex
|
47 | </label>
|
48 | </div>
|
49 |
|
50 | <div class="displayFlex lineHeight32 colorDarkGray">
|
51 |
|
52 | <label class="marginRight30 cursorPointer displayFlex itemsCenter">
|
53 | <input name="sex"
|
54 | type="radio"
|
55 | v-model="patientData.sex"
|
56 | value="female"
|
57 | class="marginRight10">
|
58 | <span class="paddingTop5">Female</span>
|
59 | </label>
|
60 |
|
61 | <label class="cursorPointer displayFlex itemsCenter">
|
62 | <input name="sex"
|
63 | type="radio"
|
64 | v-model="patientData.sex"
|
65 | value="male"
|
66 | class="marginRight10">
|
67 | <span class="paddingTop5">Male</span>
|
68 | </label>
|
69 |
|
70 | </div>
|
71 |
|
72 | <div v-if="patientForm.$wasSubmitted"
|
73 | class="marginTop12 widthTwelve colorRed fontSize14">
|
74 | <div v-if="patientForm.sex.valueMissing">
|
75 | Sex is required.
|
76 | </div>
|
77 | </div>
|
78 |
|
79 | </div>
|
80 |
|
81 |
|
82 | <div v-if="patientData.sex === 'female'"
|
83 | class="marginBottom30 widthTwelve">
|
84 |
|
85 | <div class="marginBottom10">
|
86 | <label for="email" class="colorMidGray fontSize14">
|
87 | Are you pregnant?
|
88 | </label>
|
89 | </div>
|
90 |
|
91 | <div class="displayFlex lineHeight32 colorDarkGray">
|
92 |
|
93 | <label class="marginRight30 cursorPointer displayFlex itemsCenter">
|
94 | <input name="pregnant"
|
95 | type="radio"
|
96 | v-model="patientData.pregnant"
|
97 | value="yes"
|
98 | class="marginRight10">
|
99 | <span class="paddingTop5">Yes</span>
|
100 | </label>
|
101 |
|
102 | <label class="cursorPointer displayFlex itemsCenter">
|
103 | <input name="pregnant"
|
104 | type="radio"
|
105 | v-model="patientData.pregnant"
|
106 | value="no"
|
107 | class="marginRight10">
|
108 | <span class="paddingTop5">No</span>
|
109 | </label>
|
110 |
|
111 | </div>
|
112 |
|
113 | <div v-if="patientForm.$wasSubmitted"
|
114 | class="marginTop12 widthTwelve colorRed fontSize14">
|
115 | <div v-if="patientForm.pregnant.valueMissing">
|
116 | Please specify whether you are pregnant or not.
|
117 | </div>
|
118 | </div>
|
119 |
|
120 | </div>
|
121 |
|
122 |
|
123 | <div class="marginBottom30 widthTwelve">
|
124 |
|
125 | <div class="marginBottom10">
|
126 | <label for="dob" class="colorMidGray fontSize14">
|
127 | Your date of birth
|
128 | </label>
|
129 | </div>
|
130 |
|
131 | <input id="dob"
|
132 | type="date"
|
133 | class="inputText widthTwelve"
|
134 | v-model="patientData.dob"
|
135 | required>
|
136 |
|
137 | <div v-if="patientForm.$wasSubmitted"
|
138 | class="marginTop12 widthTwelve colorRed fontSize14">
|
139 | <div v-if="patientForm.dob.valueMissing">
|
140 | Date of birth is required.
|
141 | </div>
|
142 | </div>
|
143 |
|
144 | </div>
|
145 |
|
146 | </div>
|
147 |
|
148 | <div class="flex1 padding30">
|
149 |
|
150 |
|
151 | <div class="marginBottom30">
|
152 |
|
153 | <div class="marginBottom10">
|
154 | <label for="description" class="colorMidGray fontSize14">
|
155 | The reason for your visit
|
156 | </label>
|
157 | </div>
|
158 |
|
159 | <div class="paddingBottom10 paddingTop10">
|
160 | <label class="colorDarkGray marginRight20 cursorPointer">
|
161 | <input name="reasons"
|
162 | type="checkbox"
|
163 | v-model="patientData.reasons"
|
164 | value="checkup"
|
165 | class="marginRight10">
|
166 | Checkup
|
167 | </label>
|
168 | </div>
|
169 |
|
170 | <div class="paddingBottom10 paddingTop10">
|
171 | <label class="colorDarkGray marginRight20 cursorPointer">
|
172 | <input name="reasons"
|
173 | type="checkbox"
|
174 | v-model="patientData.reasons"
|
175 | value="illness"
|
176 | class="marginRight10">
|
177 | Illness
|
178 | </label>
|
179 | </div>
|
180 |
|
181 | <div class="paddingBottom10 paddingTop10">
|
182 | <label class="colorDarkGray marginRight20 cursorPointer">
|
183 | <input name="reasons"
|
184 | type="checkbox"
|
185 | v-model="patientData.reasons"
|
186 | value="pregnancy"
|
187 | class="marginRight10">
|
188 | Pregnancy
|
189 | </label>
|
190 | </div>
|
191 |
|
192 | <div class="paddingBottom10 paddingTop10">
|
193 | <label class="colorDarkGray marginRight20 cursorPointer">
|
194 | <input name="reasons"
|
195 | type="checkbox"
|
196 | v-model="patientData.reasons"
|
197 | value="consultation"
|
198 | class="marginRight10">
|
199 | Consultation
|
200 | </label>
|
201 | </div>
|
202 |
|
203 | <div>
|
204 | <div class="paddingBottom10 paddingTop10 displayFlex itemsCenter">
|
205 | <div class="width30">
|
206 | <input name="reasons"
|
207 | type="checkbox"
|
208 | v-model="patientData.reasons"
|
209 | value="other"
|
210 | class="floatLeft">
|
211 | </div>
|
212 | <input type="text"
|
213 | placeholder="Other"
|
214 | v-model="patientData.otherReason"
|
215 | minlength="3"
|
216 | class="inputText widthTwelve"
|
217 | :required="otherReasonRequired">
|
218 | </div>
|
219 | </div>
|
220 |
|
221 | <div v-if="patientForm.$wasSubmitted"
|
222 | class="marginTop12 widthTwelve colorRed fontSize14">
|
223 | <div v-if="patientForm.reasons.valueMissing">
|
224 | Reason is required.
|
225 | </div>
|
226 | <div v-if="otherReasonRequired && !patientData.otherReason">
|
227 | Please specify the other reason for your visit.
|
228 | </div>
|
229 | </div>
|
230 |
|
231 | </div>
|
232 |
|
233 |
|
234 | <transition name="fade">
|
235 | <div v-if="formSent" class="colorOlive fontSize18 textCenter">
|
236 | Patient submitted.
|
237 | </div>
|
238 | </transition>
|
239 |
|
240 |
|
241 | <div v-if="!formSent" class="textRight fontSize20">
|
242 |
|
243 |
|
244 | <button type="reset"
|
245 | class="button circular width140 height50 marginRight30 bgGray">
|
246 | <span class="verticalMiddle">Reset</span>
|
247 | <reset-icon></reset-icon>
|
248 | </button>
|
249 |
|
250 |
|
251 | <button type="submit"
|
252 | class="button circular width150 height50"
|
253 | :class="{ 'disabled': patientForm.$isInvalid }">
|
254 | <span class="verticalMiddle">Submit</span>
|
255 | <check-icon></check-icon>
|
256 | </button>
|
257 |
|
258 | </div>
|
259 |
|
260 | </div>
|
261 |
|
262 | </form>
|
263 | </template>
|
264 |
|
265 | <script>
|
266 | import VueForm from '../../dist/vueform'
|
267 | import ResetIcon from './ResetIcon'
|
268 | import CheckIcon from './CheckIcon'
|
269 |
|
270 | export default {
|
271 | name: 'PatientForm',
|
272 | components: { ResetIcon, CheckIcon },
|
273 | data () {
|
274 | const required = () => this.patientData.sex === 'female'
|
275 | const requiredFields = [
|
276 | 'sex',
|
277 | 'reasons',
|
278 | { name: 'pregnant', required }
|
279 | ]
|
280 | return {
|
281 | formSent: false,
|
282 | patientData: { reasons: [], sex: null },
|
283 | patientForm: new VueForm({ required: requiredFields })
|
284 | }
|
285 | },
|
286 | computed: {
|
287 | otherReasonRequired () {
|
288 | const { reasons } = this.patientData
|
289 | return reasons.indexOf('other') !== -1
|
290 | }
|
291 | },
|
292 | methods: {
|
293 | submit () {
|
294 | if (this.patientForm.$isValid) {
|
295 | this.formSent = true
|
296 | console.log('VALID')
|
297 | } else {
|
298 | console.log('INVALID')
|
299 | }
|
300 | }
|
301 | }
|
302 | }
|
303 | </script>
|