Improve validation

This commit is contained in:
Peter Maquiran
2021-07-02 11:19:52 +01:00
parent a8dd092c5a
commit 351c9a2946
2 changed files with 89 additions and 6 deletions
@@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { AlertController, AnimationController, ModalController, NavParams } from '@ionic/angular';
import { Attachment } from 'src/app/models/attachment.model';
@@ -18,6 +19,10 @@ import { SearchPage } from '../../search/search.page';
})
export class EditEventPage implements OnInit {
Form: FormGroup;
validateFrom = false
postEvent: Event;
isRecurring:string;
isEventEdited: boolean;
@@ -115,7 +120,45 @@ export class EditEventPage implements OnInit {
this.router.navigate(['/home',this.caller]);
}
runValidation() {
this.validateFrom = true
}
injectValidation() {
this.Form = new FormGroup({
Subject: new FormControl(this.postEvent.Subject, [
Validators.required,
// Validators.minLength(4)
]),
Location: new FormControl(this.postEvent.Location, [
Validators.required,
]),
CalendarName: new FormControl(this.postEvent.CalendarName, [
Validators.required
]),
Categories: new FormControl(this.postEvent.Categories[0], [
Validators.required
]),
IsRecurring: new FormControl(this.postEvent.IsRecurring, [
Validators.required
]),
// participantes: new FormControl(this.taskParticipantsCc.concat(this.taskParticipants), [
// Validators.required
// ]),
})
}
save() {
this.injectValidation()
this.runValidation()
if(this.Form.invalid) return false
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc)
try{
this.eventsService.editEvent(this.postEvent, 2, 3).subscribe(async () => {