aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/admin/friends/friend-add/friend-add.component.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-09-09 22:16:51 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-09-09 22:16:51 +0200
commit4b2f33f3c6d109365090b08244d7f99ad4e69025 (patch)
tree700d3e8e14efc4172f754d75c041ec507100e897 /client/src/app/admin/friends/friend-add/friend-add.component.ts
parentab32b0fc805b92c5a1d7ac5901cb1a38e94622ca (diff)
downloadPeerTube-4b2f33f3c6d109365090b08244d7f99ad4e69025.tar.gz
PeerTube-4b2f33f3c6d109365090b08244d7f99ad4e69025.tar.zst
PeerTube-4b2f33f3c6d109365090b08244d7f99ad4e69025.zip
Client: reactive forms
Diffstat (limited to 'client/src/app/admin/friends/friend-add/friend-add.component.ts')
-rw-r--r--client/src/app/admin/friends/friend-add/friend-add.component.ts15
1 files changed, 8 insertions, 7 deletions
diff --git a/client/src/app/admin/friends/friend-add/friend-add.component.ts b/client/src/app/admin/friends/friend-add/friend-add.component.ts
index 55aed9156..68363b482 100644
--- a/client/src/app/admin/friends/friend-add/friend-add.component.ts
+++ b/client/src/app/admin/friends/friend-add/friend-add.component.ts
@@ -11,19 +11,19 @@ import { FriendService } from '../shared';
11 styles: [ require('./friend-add.component.scss') ] 11 styles: [ require('./friend-add.component.scss') ]
12}) 12})
13export class FriendAddComponent implements OnInit { 13export class FriendAddComponent implements OnInit {
14 friendAddForm: FormGroup; 14 form: FormGroup;
15 urls = [ ]; 15 urls = [ ];
16 error: string = null; 16 error: string = null;
17 17
18 constructor(private router: Router, private friendService: FriendService) {} 18 constructor(private router: Router, private friendService: FriendService) {}
19 19
20 ngOnInit() { 20 ngOnInit() {
21 this.friendAddForm = new FormGroup({}); 21 this.form = new FormGroup({});
22 this.addField(); 22 this.addField();
23 } 23 }
24 24
25 addField() { 25 addField() {
26 this.friendAddForm.addControl(`url-${this.urls.length}`, new FormControl('', [ validateUrl ])); 26 this.form.addControl(`url-${this.urls.length}`, new FormControl('', [ validateUrl ]));
27 this.urls.push(''); 27 this.urls.push('');
28 } 28 }
29 29
@@ -42,7 +42,7 @@ export class FriendAddComponent implements OnInit {
42 isFormValid() { 42 isFormValid() {
43 // Do not check the last input 43 // Do not check the last input
44 for (let i = 0; i < this.urls.length - 1; i++) { 44 for (let i = 0; i < this.urls.length - 1; i++) {
45 if (!this.friendAddForm.controls[`url-${i}`].valid) return false; 45 if (!this.form.controls[`url-${i}`].valid) return false;
46 } 46 }
47 47
48 const lastIndex = this.urls.length - 1; 48 const lastIndex = this.urls.length - 1;
@@ -50,13 +50,13 @@ export class FriendAddComponent implements OnInit {
50 if (this.urls[lastIndex] === '' && lastIndex !== 0) { 50 if (this.urls[lastIndex] === '' && lastIndex !== 0) {
51 return true; 51 return true;
52 } else { 52 } else {
53 return this.friendAddForm.controls[`url-${lastIndex}`].valid; 53 return this.form.controls[`url-${lastIndex}`].valid;
54 } 54 }
55 } 55 }
56 56
57 removeField(index: number) { 57 removeField(index: number) {
58 // Remove the last control 58 // Remove the last control
59 this.friendAddForm.removeControl(`url-${this.urls.length - 1}`); 59 this.form.removeControl(`url-${this.urls.length - 1}`);
60 this.urls.splice(index, 1); 60 this.urls.splice(index, 1);
61 } 61 }
62 62
@@ -94,7 +94,8 @@ export class FriendAddComponent implements OnInit {
94 private getNotEmptyUrls() { 94 private getNotEmptyUrls() {
95 const notEmptyUrls = []; 95 const notEmptyUrls = [];
96 96
97 this.urls.forEach((url) => { 97 Object.keys(this.form.value).forEach((urlKey) => {
98 const url = this.form.value[urlKey];
98 if (url !== '') notEmptyUrls.push(url); 99 if (url !== '') notEmptyUrls.push(url);
99 }); 100 });
100 101