Browse Source

Validation added to property screens

master
George Williams 5 years ago
parent
commit
1a2470d1d9
2 changed files with 159 additions and 45 deletions
  1. 70
    5
      src/components/property/propertyCreate.vue
  2. 89
    40
      src/components/property/propertyeditPage.vue

+ 70
- 5
src/components/property/propertyCreate.vue View File

@@ -46,7 +46,7 @@
46 46
                     class="form-control"
47 47
                     name="propertyUsageType"
48 48
                     id="propertyUsageType"
49
-                    v-model="property.propertyUsageType"
49
+                    v-model="propertyType"
50 50
                     @change="TypeChanged"
51 51
                   >
52 52
                     <option value="Residential">Residential</option>
@@ -55,9 +55,10 @@
55 55
                 </div>
56 56
               </div>
57 57
             </div>
58
+            <br />
58 59
             <div class="form-group row">
59 60
               <div class="col-md-4">
60
-                <label>Property Type</label>
61
+                <label>Property Type *</label>
61 62
                 <div class="input-group-prepend">
62 63
                   <span class="input-group-text" style="color: #60CBEB">
63 64
                     <b>T</b>
@@ -67,6 +68,7 @@
67 68
                     name="propertyType"
68 69
                     id="propertyType"
69 70
                     v-model="property.propertyTypeId"
71
+                    @change="PropertyTypeSelected"
70 72
                   >
71 73
                     <option value="0">Please select type</option>
72 74
                     <option v-for="item in propertyTypes" :value="item.id" :key="item.id">{{
@@ -74,6 +76,9 @@
74 76
                     }}</option>
75 77
                   </select>
76 78
                 </div>
79
+                <div v-if="showPropertyTypeError">
80
+                  <p class="alert myError">Please select a type</p>
81
+                </div>
77 82
               </div>
78 83
               <div v-if="propertyType === 'Commercial'" class="col-md-4">
79 84
                 <label>Property Name</label>
@@ -137,7 +142,7 @@
137 142
                 </div>
138 143
               </div>
139 144
               <div class="col-md-6" style="margin-bottom: 1em">
140
-                <label>Province</label>
145
+                <label>Province *</label>
141 146
                 <div class="input-group-prepend">
142 147
                   <span class="input-group-text">
143 148
                     <eva-icon name="home-outline" fill="#60CBEB"></eva-icon>
@@ -155,10 +160,13 @@
155 160
                     }}</option>
156 161
                   </select>
157 162
                 </div>
163
+                <div v-if="showProvinceError">
164
+                  <p class="alert myError">Please select a Province</p>
165
+                </div>
158 166
               </div>
159 167
 
160 168
               <div class="col-md-6" style="margin-bottom: 1em">
161
-                <label>City</label>
169
+                <label>City *</label>
162 170
                 <div class="input-group-prepend">
163 171
                   <span class="input-group-text">
164 172
                     <eva-icon name="home-outline" fill="#60CBEB"></eva-icon>
@@ -176,9 +184,12 @@
176 184
                     }}</option>
177 185
                   </select>
178 186
                 </div>
187
+                <div v-if="showCityError">
188
+                  <p class="alert myError">Please select a City</p>
189
+                </div>
179 190
               </div>
180 191
               <div class="col-md-6" style="margin-bottom: 1em">
181
-                <label>Suburb</label>
192
+                <label>Suburb *</label>
182 193
                 <div class="input-group-prepend">
183 194
                   <span class="input-group-text">
184 195
                     <eva-icon name="home-outline" fill="#60CBEB"></eva-icon>
@@ -196,6 +207,9 @@
196 207
                     }}</option>
197 208
                   </select>
198 209
                 </div>
210
+                <div v-if="showSuburbError">
211
+                  <p class="alert myError">Please select a Suburb</p>
212
+                </div>
199 213
               </div>
200 214
               <div class="col-md-6" style="margin-bottom: 1em">
201 215
                 <label>Postal Code</label>
@@ -346,6 +360,13 @@
346 360
             >
347 361
               Save
348 362
             </button>
363
+            <div
364
+              v-if="showPropertyTypeError || showProvinceError || showCityError || showSuburbError"
365
+            >
366
+              <p class="alert myError">
367
+                Missing fields. Please fill in all required fields. Marked with *
368
+              </p>
369
+            </div>
349 370
             <div v-if="wait" id="preloader"></div>
350 371
           </form>
351 372
         </div>
@@ -386,6 +407,10 @@ export default {
386 407
         [{ indent: '-1' }, { indent: '+1' }],
387 408
       ],
388 409
       error: '',
410
+      showPropertyTypeError: false,
411
+      showProvinceError: false,
412
+      showCityError: false,
413
+      showSuburbError: false,
389 414
     };
390 415
   },
391 416
   methods: {
@@ -408,6 +433,28 @@ export default {
408 433
       this.propertyType = this.property.propertyUsageType;
409 434
     },
410 435
     SubmitData() {
436
+      if (this.property.propertyTypeId === 0) {
437
+        this.showPropertyTypeError = true;
438
+      }
439
+      if (this.property.provinceId === 0) {
440
+        this.showProvinceError = true;
441
+      }
442
+      if (this.property.cityId === 0) {
443
+        this.showCityError = true;
444
+      }
445
+      if (this.property.suburbId === 0) {
446
+        this.showSuburbError = true;
447
+      }
448
+
449
+      if (
450
+        this.showPropertyTypeError
451
+        || this.showProvinceError
452
+        || this.showCityError
453
+        || this.showSuburbError
454
+      ) {
455
+        return;
456
+      }
457
+
411 458
       this.wait = true;
412 459
       if (this.salesType === 'Sale') {
413 460
         this.property.isSale = true;
@@ -440,10 +487,20 @@ export default {
440 487
     Close() {
441 488
       this.$router.push('/property/admin/list/my');
442 489
     },
490
+    PropertyTypeSelected(item) {
491
+      if (item.target.options.selectedIndex > 0) {
492
+        this.showPropertyTypeError = false;
493
+      } else {
494
+        this.showPropertyTypeError = true;
495
+      }
496
+    },
443 497
     ProvinceSelected(item) {
444 498
       if (item.target.options.selectedIndex > 0) {
445 499
         this.selectedProvince = this.provinces[item.target.options.selectedIndex - 1].description;
446 500
         this.getCities(Object.assign({}, { province: this.selectedProvince }));
501
+        this.showProvinceError = false;
502
+      } else {
503
+        this.showProvinceError = true;
447 504
       }
448 505
     },
449 506
     CitySelected(item) {
@@ -452,10 +509,18 @@ export default {
452 509
         this.getSuburbs(
453 510
           Object.assign({}, { province: this.selectedProvince, city: this.selectedCity }),
454 511
         );
512
+        this.showCityError = false;
513
+      } else {
514
+        this.showCityError = true;
455 515
       }
456 516
     },
457 517
     getPostalCode(item) {
458 518
       this.property.addressLine3 = this.suburbs[item.target.options.selectedIndex - 1].postalCode;
519
+      if (item.target.options.selectedIndex > 0) {
520
+        this.showSuburbError = false;
521
+      } else {
522
+        this.showSuburbError = true;
523
+      }
459 524
     },
460 525
     loadedImages(values) {
461 526
       this.images = values;

+ 89
- 40
src/components/property/propertyeditPage.vue View File

@@ -53,6 +53,7 @@
53 53
                 </div>
54 54
               </div>
55 55
             </div>
56
+            <br />
56 57
             <div class="form-group row">
57 58
               <div class="col-md-4">
58 59
                 <label>Sale Type</label>
@@ -64,11 +65,14 @@
64 65
                   :mayEdit="mayEdit"
65 66
                   @UpdateValue="UpdateValue"
66 67
                 />
68
+                <div v-if="showPropertyTypeError">
69
+                  <p class="alert myError">Please select a Sales Type</p>
70
+                </div>
67 71
               </div>
68 72
             </div>
69 73
             <div class="form-group row">
70 74
               <div class="col-md-4">
71
-                <label>Property Type</label>
75
+                <label>Property Type *</label>
72 76
                 <propField
73 77
                   :display="property.propertyType ? property.propertyType.description : ''"
74 78
                   :editType="'selector'"
@@ -122,7 +126,7 @@
122 126
                 />
123 127
               </div>
124 128
               <div class="col-md-6" style="margin-bottom: 1em">
125
-                <label>Province</label>
129
+                <label>Province *</label>
126 130
                 <propField
127 131
                   :display="property.province ? property.province.description : ''"
128 132
                   :editType="'selector'"
@@ -131,10 +135,12 @@
131 135
                   :mayEdit="mayEdit"
132 136
                   @UpdateValue="UpdateValue"
133 137
                 />
138
+                <div v-if="showProvinceError">
139
+                  <p class="alert myError">Please select a Province</p>
140
+                </div>
134 141
               </div>
135
-
136 142
               <div class="col-md-6" style="margin-bottom: 1em">
137
-                <label>City</label>
143
+                <label>City *</label>
138 144
                 <propField
139 145
                   :display="property.city ? property.city.description : ''"
140 146
                   :editType="'selector'"
@@ -143,9 +149,12 @@
143 149
                   :mayEdit="mayEdit"
144 150
                   @UpdateValue="UpdateValue"
145 151
                 />
152
+                <div v-if="showCityError">
153
+                  <p class="alert myError">Please select a City</p>
154
+                </div>
146 155
               </div>
147 156
               <div class="col-md-6" style="margin-bottom: 1em">
148
-                <label>Suburb</label>
157
+                <label>Suburb * </label>
149 158
                 <propField
150 159
                   :display="property.suburb ? property.suburb.description : ''"
151 160
                   :editType="'selector'"
@@ -154,6 +163,9 @@
154 163
                   :mayEdit="mayEdit"
155 164
                   @UpdateValue="UpdateValue"
156 165
                 />
166
+                <div v-if="showSuburbError">
167
+                  <p class="alert myError">Please select a suburb</p>
168
+                </div>
157 169
               </div>
158 170
               <div class="col-md-6" style="margin-bottom: 1em">
159 171
                 <label>Postal Code</label>
@@ -196,13 +208,16 @@
196 208
                 <label for="Property Description">Description</label>
197 209
                 <vue-editor v-model="property.description" :editor-toolbar="customToolbar" />
198 210
                 <br />
199
-                <p>* A listing fee of R380 including VAT is payable to list your Property on the Uni-Vate website</p>
211
+                <p>
212
+                  * A listing fee of R380 including VAT is payable to list your Property on the
213
+                  Uni-Vate website
214
+                </p>
200 215
               </div>
201 216
             </div>
202 217
             <div class="form-group row" />
203 218
             <div
204 219
               class="col-md-6"
205
-              v-if="propertyType === 'Residential' & propertyOverviewFields.length > 0"
220
+              v-if="(propertyType === 'Residential') & (propertyOverviewFields.length > 0)"
206 221
             >
207 222
               <div v-for="(item, i) in propertyOverviewFields[0].fields" :key="item.id">
208 223
                 <label>{{ item.name }}</label>
@@ -243,6 +258,7 @@
243 258
                   @UpdateValue="UpdateValue"
244 259
                 />
245 260
               </div>
261
+              <br />
246 262
             </div>
247 263
             <div class="form-group row" />
248 264
             <div class="row">
@@ -321,13 +337,27 @@
321 337
               class="btn btn-b-n"
322 338
               style="width: 85px; height:40px;"
323 339
               :disabled="!mayEdit"
324
-            >Save</button>
340
+            >
341
+              Save
342
+            </button>
325 343
             <button
326 344
               type="button"
327 345
               @click="Close()"
328 346
               class="btn btn-b-n"
329 347
               style="width: 85px; height:40px;"
330
-            >Close</button>
348
+              :disabled="
349
+                showPropertyTypeError || showProvinceError || showCityError || showSuburbError
350
+              "
351
+            >
352
+              Close
353
+            </button>
354
+            <div
355
+              v-if="showPropertyTypeError || showProvinceError || showCityError || showSuburbError"
356
+            >
357
+              <p class="alert myError">
358
+                Missing fields. Please fill in all required fields. Marked with *
359
+              </p>
360
+            </div>
331 361
             <div v-if="wait" id="preloader"></div>
332 362
           </form>
333 363
         </div>
@@ -339,7 +369,6 @@
339 369
 <script>
340 370
 import { mapState, mapActions } from 'vuex';
341 371
 import { VueEditor } from 'vue2-editor';
342
-import { setTimeout } from 'timers';
343 372
 import ImageLoad from './propertyImage.vue';
344 373
 import propField from './propertyFieldEditor.vue';
345 374
 
@@ -361,12 +390,7 @@ export default {
361 390
       customToolbar: [
362 391
         [{ header: [false, 1, 2, 3, 4, 5, 6] }],
363 392
         ['bold', 'italic', 'underline', 'strike'],
364
-        [
365
-          { align: '' },
366
-          { align: 'center' },
367
-          { align: 'right' },
368
-          { align: 'justify' },
369
-        ],
393
+        [{ align: '' }, { align: 'center' }, { align: 'right' }, { align: 'justify' }],
370 394
         [{ list: 'ordered' }, { list: 'bullet' }, { list: 'check' }],
371 395
         [{ script: 'sub' }, { script: 'super' }],
372 396
         [{ indent: '-1' }, { indent: '+1' }],
@@ -379,6 +403,10 @@ export default {
379 403
         { id: 'Month', description: 'Month' },
380 404
         { id: 'Day', description: 'Day' },
381 405
       ],
406
+      showPropertyTypeError: false,
407
+      showProvinceError: false,
408
+      showCityError: false,
409
+      showSuburbError: false,
382 410
     };
383 411
   },
384 412
   methods: {
@@ -389,19 +417,13 @@ export default {
389 417
       'getListsForPropertyEdit',
390 418
     ]),
391 419
     ...mapActions('property', ['getPropertyTypes']),
392
-    ...mapActions('propertyEdit', [
393
-      'getSavedPropertyData',
394
-      'updateProperty',
395
-      'mayEditProperty',
396
-    ]),
420
+    ...mapActions('propertyEdit', ['getSavedPropertyData', 'updateProperty', 'mayEditProperty']),
397 421
     UpdateValue(item) {
398 422
       if (item.isUDF) {
399 423
         if (item.isPropOverview) {
400
-          this.propertyOverviewFields[0].fields[item.arrayIndex].value =            item.value;
424
+          this.propertyOverviewFields[0].fields[item.arrayIndex].value = item.value;
401 425
         } else if (item.isPropOverview === false) {
402
-          this.propertyFields[item.arrayIndex].fields[
403
-            item.arrayItemIndex
404
-          ].value = item.value;
426
+          this.propertyFields[item.arrayIndex].fields[item.arrayItemIndex].value = item.value;
405 427
         }
406 428
       } else if (!item.isUDF) {
407 429
         if (item.fieldName) {
@@ -413,10 +435,15 @@ export default {
413 435
             this.property.isSale = isSaleValue;
414 436
           }
415 437
           if (item.fieldName === 'propertyType') {
416
-            this.property.propertyType = this.propertyTypes.find(
417
-              pt => pt.description === item.value,
418
-            );
419
-            this.property.propertyTypeId = this.property.propertyType.id;
438
+            if (item.value !== '') {
439
+              this.property.propertyType = this.propertyTypes.find(
440
+                pt => pt.description === item.value,
441
+              );
442
+              this.property.propertyTypeId = this.property.propertyType.id;
443
+              this.showPropertyTypeError = false;
444
+            } else {
445
+              this.showPropertyTypeError = true;
446
+            }
420 447
           }
421 448
           if (item.fieldName === 'propertyName') {
422 449
             this.property.propertyName = item.value;
@@ -435,14 +462,15 @@ export default {
435 462
           }
436 463
           if (item.fieldName === 'province') {
437 464
             if (item.value !== '') {
438
-              this.property.province = this.provinces.find(
439
-                p => p.description === item.value,
440
-              );
465
+              this.property.province = this.provinces.find(p => p.description === item.value);
441 466
               this.property.provinceId = this.property.province.id;
442 467
               this.getCities(Object.assign({}, { province: item.value }));
443 468
               this.property.city = null;
444 469
               this.property.suburb = null;
445 470
               this.property.addressLine3 = '';
471
+              this.showProvinceError = false;
472
+              this.showCityError = true;
473
+              this.showSuburbError = true;
446 474
             } else {
447 475
               this.property.province = null;
448 476
               this.property.city = null;
@@ -450,13 +478,12 @@ export default {
450 478
               this.property.addressLine3 = '';
451 479
               this.cities = [];
452 480
               this.suburbs = [];
481
+              this.showProvinceError = true;
453 482
             }
454 483
           }
455 484
           if (item.fieldName === 'city') {
456 485
             if (item.value !== '') {
457
-              const newCity = this.cities.find(
458
-                p => p.description === item.value,
459
-              );
486
+              const newCity = this.cities.find(p => p.description === item.value);
460 487
               this.property.city = newCity;
461 488
               this.property.cityId = newCity.id;
462 489
               this.getSuburbs(
@@ -470,24 +497,27 @@ export default {
470 497
               );
471 498
               this.property.suburb = null;
472 499
               this.property.addressLine3 = '';
500
+              this.showCityError = false;
501
+              this.showSuburbError = true;
473 502
             } else {
474 503
               this.property.city = null;
475 504
               this.property.suburb = null;
476 505
               this.property.addressLine3 = '';
477 506
               this.suburbs = [];
507
+              this.showCityError = true;
478 508
             }
479 509
           }
480 510
           if (item.fieldName === 'suburb') {
481 511
             if (item.value !== '') {
482
-              const newSuburb = this.suburbs.find(
483
-                p => p.description === item.value,
484
-              );
512
+              const newSuburb = this.suburbs.find(p => p.description === item.value);
485 513
               this.property.suburb = newSuburb;
486 514
               this.property.suburbId = newSuburb.id;
487 515
               this.property.addressLine3 = this.property.suburb.postalCode;
516
+              this.showSuburbError = false;
488 517
             } else {
489 518
               this.property.suburb = null;
490 519
               this.property.addressLine3 = '';
520
+              this.showSuburbError = true;
491 521
             }
492 522
           }
493 523
           if (item.fieldName === 'price') {
@@ -509,8 +539,28 @@ export default {
509 539
       this.propertyType = this.property.propertyUsageType;
510 540
     },
511 541
     SubmitData() {
512
-      this.wait = true;
542
+      if (this.property.propertyTypeId === 0) {
543
+        this.showPropertyTypeError = true;
544
+      }
545
+      if (this.property.province === null) {
546
+        this.showProvinceError = true;
547
+      }
548
+      if (this.property.city === null) {
549
+        this.showCityError = true;
550
+      }
551
+      if (this.property.suburb === null) {
552
+        this.showSuburbError = true;
553
+      }
513 554
 
555
+      if (
556
+        this.showPropertyTypeError
557
+        || this.showProvinceError
558
+        || this.showCityError
559
+        || this.showSuburbError
560
+      ) {
561
+        return;
562
+      }
563
+      this.wait = true;
514 564
       this.newPropertyImages.propertyId = this.property.id;
515 565
       this.newPropertyImages.Images = [];
516 566
       // eslint-disable-next-line no-plusplus
@@ -524,7 +574,6 @@ export default {
524 574
           isDefault: setAsDefault,
525 575
         });
526 576
       }
527
-
528 577
       this.property.propertyImages = this.propertyImages;
529 578
       // eslint-disable-next-line no-plusplus
530 579
       for (let i = 0; i < this.property.propertyImages.length; i++) {

Loading…
Cancel
Save