diff options
author | Chocobozzz <me@florianbigard.com> | 2020-08-11 16:07:53 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-08-11 16:18:42 +0200 |
commit | 52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4 (patch) | |
tree | 887d2b6106548ad23cf016d82baf1977198027d9 /client/src/app/shared/shared-forms/select/select-tags.component.ts | |
parent | 3d25d5de33d8aa0ba00d7514522b25d22bf0e0a1 (diff) | |
download | PeerTube-52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4.tar.gz PeerTube-52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4.tar.zst PeerTube-52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4.zip |
Use ng select for multiselect
Diffstat (limited to 'client/src/app/shared/shared-forms/select/select-tags.component.ts')
-rw-r--r-- | client/src/app/shared/shared-forms/select/select-tags.component.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-forms/select/select-tags.component.ts b/client/src/app/shared/shared-forms/select/select-tags.component.ts new file mode 100644 index 000000000..93d199037 --- /dev/null +++ b/client/src/app/shared/shared-forms/select/select-tags.component.ts | |||
@@ -0,0 +1,38 @@ | |||
1 | import { Component, Input, forwardRef } from '@angular/core' | ||
2 | import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms' | ||
3 | |||
4 | @Component({ | ||
5 | selector: 'my-select-tags', | ||
6 | styleUrls: [ './select-shared.component.scss', './select-tags.component.scss' ], | ||
7 | templateUrl: './select-tags.component.html', | ||
8 | providers: [ | ||
9 | { | ||
10 | provide: NG_VALUE_ACCESSOR, | ||
11 | useExisting: forwardRef(() => SelectTagsComponent), | ||
12 | multi: true | ||
13 | } | ||
14 | ] | ||
15 | }) | ||
16 | export class SelectTagsComponent implements ControlValueAccessor { | ||
17 | @Input() availableItems: string[] = [] | ||
18 | @Input() selectedItems: string[] = [] | ||
19 | |||
20 | propagateChange = (_: any) => { /* empty */ } | ||
21 | |||
22 | writeValue (items: string[]) { | ||
23 | this.selectedItems = items | ||
24 | this.propagateChange(this.selectedItems) | ||
25 | } | ||
26 | |||
27 | registerOnChange (fn: (_: any) => void) { | ||
28 | this.propagateChange = fn | ||
29 | } | ||
30 | |||
31 | registerOnTouched () { | ||
32 | // Unused | ||
33 | } | ||
34 | |||
35 | onModelChange () { | ||
36 | this.propagateChange(this.selectedItems) | ||
37 | } | ||
38 | } | ||