This commit is contained in:
parent
754408dfa3
commit
a1c46c2648
|
@ -22,10 +22,10 @@
|
|||
<td>
|
||||
<input type="text" [(ngModel)]="event!.location">
|
||||
</td>
|
||||
<td class="{{showDateError || requiredFieldsMissing? 'has-error' : ''}}">
|
||||
<td class="{{requiredFieldsMissing? 'has-error' : ''}}">
|
||||
{{event?.createdBy}}
|
||||
</td>
|
||||
<td>
|
||||
<td class="{{invalidUrlError? 'has-error' : ''}}">
|
||||
<input type="text" [(ngModel)]="event!.url">
|
||||
</td>
|
||||
<td>
|
||||
|
@ -33,6 +33,7 @@
|
|||
<p class="has-error" *ngIf="showDateError">Start Date must not be after end date!</p>
|
||||
<p class="has-error" *ngIf="requiredFieldsMissing">Required fields are missing!</p>
|
||||
<p class="has-error" *ngIf="showCreateError">Error creating event. Please try again.</p>
|
||||
<p class="has-error" *ngIf="invalidUrlError">Invalid URL, please only provide valid ones!</p>
|
||||
</td>
|
||||
<td>
|
||||
<button (click)="triggerDelete()">Delete</button>
|
||||
|
|
|
@ -16,6 +16,7 @@ export class EventComponent implements OnInit {
|
|||
newEndDate: string | undefined;
|
||||
newEndTime: string | undefined;
|
||||
showDateError: boolean = false;
|
||||
invalidUrlError: boolean = false;
|
||||
requiredFieldsMissing: boolean = false;
|
||||
showCreateError: boolean = false;
|
||||
@Output() deleteEvent = new EventEmitter<number>();
|
||||
|
@ -53,6 +54,11 @@ export class EventComponent implements OnInit {
|
|||
return;
|
||||
}
|
||||
|
||||
if(!this.checkEventValidUrl()) {
|
||||
this.invalidUrlError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.event.eventId === undefined) {
|
||||
this.api.createEvent(this.event).subscribe((res: any) => {
|
||||
console.log(res);
|
||||
|
@ -148,4 +154,27 @@ export class EventComponent implements OnInit {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
checkEventValidUrl(): boolean {
|
||||
if(this.isNullOrBlank(this.event!.url)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const urlRegex = /^(https?:\/\/)?((www\.)?([a-z0-9äöü]*\.)+[a-z]{2,10}.*)$/i;
|
||||
|
||||
let validUrl = urlRegex.test(this.event!.url);
|
||||
|
||||
if(validUrl){
|
||||
let match = this.event!.url.match(urlRegex);
|
||||
if(match) {
|
||||
console.log(match);
|
||||
let url = 'https://' + match[2];
|
||||
this.event!.url = url;
|
||||
} else {
|
||||
validUrl = false;
|
||||
}
|
||||
}
|
||||
|
||||
return validUrl;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user