Skip to content

Commit

Permalink
feat: validation of playlist url
Browse files Browse the repository at this point in the history
  • Loading branch information
4gray committed Dec 26, 2020
1 parent 041cd61 commit da2fe5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/app/home/url-upload/url-upload.component.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<form (ngSubmit)="urlAdded.emit(playlistUrl.value)">
<form (ngSubmit)="urlAdded.emit(form.value.playlistUrl)" [formGroup]="form">
<mat-form-field class="full-width">
<input
type="url"
matInput
placeholder="Playlist URL (m3u, m3u8)"
#playlistUrl
formControlName="playlistUrl"
/>
</mat-form-field>
<button
mat-flat-button
[disabled]="!playlistUrl.value"
[disabled]="!form.valid"
color="primary"
type="submit"
>
Expand Down
19 changes: 19 additions & 0 deletions src/app/home/url-upload/url-upload.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, Output, EventEmitter } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
selector: 'app-url-upload',
Expand All @@ -8,4 +9,22 @@ import { Component, Output, EventEmitter } from '@angular/core';
export class UrlUploadComponent {
/** Emits url string to the parent component on form submit */
@Output() urlAdded: EventEmitter<string> = new EventEmitter();

/** Form group with playlist url */
form: FormGroup;

/**
* Creates an instance of component
* @param fb angulars form builder
*/
constructor(private fb: FormBuilder) {
const urlRegex = '(https?://.*?.(m3u|m3u8))';
this.form = this.fb.group({
playlistUrl: [
'',
// eslint-disable-next-line @typescript-eslint/unbound-method
[Validators.required, Validators.pattern(urlRegex)],
],
});
}
}

0 comments on commit da2fe5e

Please sign in to comment.