1 |
60413
|
k.triantaf
|
import {
|
2 |
60688
|
k.triantaf
|
Component,
|
3 |
|
|
ElementRef,
|
4 |
|
|
EventEmitter,
|
5 |
|
|
HostListener,
|
6 |
60413
|
k.triantaf
|
Input,
|
7 |
|
|
OnChanges,
|
8 |
|
|
OnDestroy,
|
9 |
|
|
OnInit,
|
10 |
|
|
Output,
|
11 |
|
|
SimpleChanges,
|
12 |
|
|
ViewChild
|
13 |
|
|
} from "@angular/core";
|
14 |
60968
|
k.triantaf
|
import {AbstractControl, FormArray, FormControl, ValidatorFn} from "@angular/forms";
|
15 |
59831
|
k.triantaf
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
16 |
60310
|
k.triantaf
|
import {Observable, of, Subscription} from "rxjs";
|
17 |
59618
|
k.triantaf
|
import {MatSelect} from "@angular/material/select";
|
18 |
60310
|
k.triantaf
|
import {MatAutocompleteSelectedEvent} from "@angular/material/autocomplete";
|
19 |
|
|
import {map, startWith} from "rxjs/operators";
|
20 |
60688
|
k.triantaf
|
import {MatChipInputEvent} from "@angular/material/chips";
|
21 |
57673
|
k.triantaf
|
|
22 |
57941
|
k.triantaf
|
|
23 |
|
|
export interface Option {
|
24 |
|
|
icon?: string,
|
25 |
|
|
iconClass?: string,
|
26 |
|
|
value: any,
|
27 |
|
|
label: string
|
28 |
|
|
}
|
29 |
|
|
|
30 |
57673
|
k.triantaf
|
@Component({
|
31 |
|
|
selector: '[dashboard-input]',
|
32 |
|
|
template: `
|
33 |
60310
|
k.triantaf
|
<div *ngIf="label && type != 'checkbox'"
|
34 |
|
|
class="uk-text-bold uk-form-label uk-margin-small-bottom">{{label + (required ? ' *' : '')}}</div>
|
35 |
60456
|
k.triantaf
|
<div *ngIf="hint" class="uk-margin-bottom uk-form-hint">{{hint}}</div>
|
36 |
60413
|
k.triantaf
|
<div class="uk-grid uk-flex" [ngClass]="'uk-flex-' + flex" [class.uk-grid-small]="gridSmall" uk-grid>
|
37 |
59618
|
k.triantaf
|
<ng-content></ng-content>
|
38 |
60310
|
k.triantaf
|
<div [class.uk-hidden]="hideControl" class="uk-width-expand uk-position-relative"
|
39 |
|
|
[class.uk-flex-first]="!extraLeft">
|
40 |
60182
|
k.triantaf
|
<ng-template [ngIf]="icon && formControl.enabled">
|
41 |
59731
|
k.triantaf
|
<span class="uk-text-muted" [ngClass]="iconLeft?('left'):'right'">
|
42 |
|
|
<icon [name]="icon"></icon>
|
43 |
|
|
</span>
|
44 |
|
|
</ng-template>
|
45 |
60182
|
k.triantaf
|
<ng-template [ngIf]="formControl.disabled">
|
46 |
|
|
<span class="uk-text-muted left">
|
47 |
|
|
<icon [name]="'lock'"></icon>
|
48 |
|
|
</span>
|
49 |
|
|
</ng-template>
|
50 |
60568
|
k.triantaf
|
<ng-template [ngIf]="type === 'text' || type === 'URL' || type === 'logoURL'">
|
51 |
60413
|
k.triantaf
|
<div [ngClass]="inputClass"
|
52 |
|
|
[class.uk-form-danger]="formControl.invalid && formControl.touched"
|
53 |
60824
|
k.triantaf
|
[attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':null">
|
54 |
60823
|
k.triantaf
|
<input #input class="uk-input" [placeholder]="placeholder" [formControl]="formControl">
|
55 |
60413
|
k.triantaf
|
</div>
|
56 |
59618
|
k.triantaf
|
</ng-template>
|
57 |
|
|
<ng-template [ngIf]="type === 'textarea'">
|
58 |
60448
|
k.triantaf
|
<div [ngClass]="inputClass" class="uk-padding-remove-right"
|
59 |
60413
|
k.triantaf
|
[class.uk-form-danger]="formControl.invalid && formControl.touched"
|
60 |
60824
|
k.triantaf
|
[attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':null">
|
61 |
60456
|
k.triantaf
|
<textarea class="uk-textarea"
|
62 |
60413
|
k.triantaf
|
[rows]="rows" [placeholder]="placeholder"
|
63 |
|
|
[formControl]="formControl">
|
64 |
|
|
</textarea>
|
65 |
|
|
<div class="tools" [class.focused]="focused">
|
66 |
|
|
<ng-content select="[options]"></ng-content>
|
67 |
|
|
</div>
|
68 |
|
|
</div>
|
69 |
59618
|
k.triantaf
|
</ng-template>
|
70 |
|
|
<ng-template [ngIf]="type === 'select'">
|
71 |
60413
|
k.triantaf
|
<div [ngClass]="inputClass"
|
72 |
60310
|
k.triantaf
|
[attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':null"
|
73 |
|
|
[class.clickable]="formControl.enabled"
|
74 |
|
|
[class.uk-form-danger]="formControl.invalid && formControl.touched" (click)="openSelect()">
|
75 |
59618
|
k.triantaf
|
<mat-form-field class="uk-width-1-1">
|
76 |
60310
|
k.triantaf
|
<mat-select #select [required]="required" [value]="null"
|
77 |
|
|
(openedChange)="stopPropagation()" [formControl]="formControl"
|
78 |
|
|
[disableOptionCentering]="true">
|
79 |
59627
|
k.triantaf
|
<mat-option *ngIf="placeholder" class="uk-hidden" [value]="''">{{placeholder}}</mat-option>
|
80 |
61047
|
konstantin
|
<mat-option *ngFor="let option of options" [value]="option.value" [attr.uk-tooltip]="option.label">
|
81 |
59618
|
k.triantaf
|
{{option.label}}
|
82 |
|
|
</mat-option>
|
83 |
|
|
</mat-select>
|
84 |
|
|
</mat-form-field>
|
85 |
|
|
</div>
|
86 |
|
|
</ng-template>
|
87 |
60674
|
k.triantaf
|
<ng-template [ngIf]="type === 'autocomplete'">
|
88 |
|
|
<div [ngClass]="inputClass"
|
89 |
|
|
[attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':null"
|
90 |
|
|
[class.clickable]="formControl.enabled"
|
91 |
|
|
[class.uk-form-danger]="formControl.invalid && formControl.touched" (click)="openSelect()">
|
92 |
|
|
<mat-form-field class="uk-width-1-1">
|
93 |
|
|
<mat-chip-list #chipList>
|
94 |
60688
|
k.triantaf
|
<mat-chip *ngIf="formControl.value" [selectable]="false" [removable]="removable"
|
95 |
60674
|
k.triantaf
|
[attr.uk-tooltip]="getLabel(formControl.value)">
|
96 |
60688
|
k.triantaf
|
<span class="uk-flex uk-flex-middle uk-width-1-1">
|
97 |
60674
|
k.triantaf
|
<span class="uk-width-expand uk-text-truncate" [class.uk-text-small]="smallChip">{{getLabel(formControl.value)}}</span>
|
98 |
|
|
<icon name="remove_circle" class="mat-chip-remove" [flex]="true" [ratio]="smallChip?0.8:1"
|
99 |
|
|
(click)="resetSearch($event)"></icon>
|
100 |
|
|
</span>
|
101 |
|
|
</mat-chip>
|
102 |
|
|
<div [class.uk-hidden]="formControl.value" class="uk-width-expand uk-position-relative chip-input">
|
103 |
60968
|
k.triantaf
|
<input #searchInput [formControl]="searchControl" [matAutocomplete]="auto"
|
104 |
60674
|
k.triantaf
|
[matChipInputFor]="chipList" [matAutocompleteConnectedTo]="origin">
|
105 |
60688
|
k.triantaf
|
<div *ngIf="placeholder && !searchInput.value" class="placeholder uk-width-1-1"
|
106 |
60674
|
k.triantaf
|
(click)="searchInput.focus()">{{placeholder}}</div>
|
107 |
|
|
</div>
|
108 |
|
|
<div class="uk-width-1-1 uk-invisible" matAutocompleteOrigin #origin="matAutocompleteOrigin"></div>
|
109 |
|
|
</mat-chip-list>
|
110 |
|
|
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="formControl.setValue($event.option.value)" [class]="panelClass" [panelWidth]="panelWidth">
|
111 |
61047
|
konstantin
|
<mat-option *ngFor="let option of filteredOptions | async" [value]="option.value" [attr.uk-tooltip]="option.label">
|
112 |
60674
|
k.triantaf
|
{{option.label}}
|
113 |
|
|
</mat-option>
|
114 |
|
|
</mat-autocomplete>
|
115 |
|
|
</mat-form-field>
|
116 |
|
|
</div>
|
117 |
|
|
</ng-template>
|
118 |
60310
|
k.triantaf
|
<ng-template [ngIf]="type === 'chips'">
|
119 |
60413
|
k.triantaf
|
<div [ngClass]="inputClass"
|
120 |
60310
|
k.triantaf
|
[attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':null"
|
121 |
|
|
[class.clickable]="formControl.enabled"
|
122 |
60968
|
k.triantaf
|
[class.uk-form-danger]="formControl.invalid && searchControl.invalid && searchControl.touched" (click)="openSelect()">
|
123 |
60310
|
k.triantaf
|
<mat-form-field class="uk-width-1-1">
|
124 |
60448
|
k.triantaf
|
<mat-chip-list #chipList>
|
125 |
|
|
<mat-chip *ngFor="let chip of formAsArray.controls; let i=index" [selectable]="false"
|
126 |
|
|
[removable]="removable" [attr.uk-tooltip]="getLabel(chip.value)">
|
127 |
60688
|
k.triantaf
|
<span class="uk-flex uk-flex-middle uk-width-1-1">
|
128 |
60570
|
k.triantaf
|
<span class="uk-width-expand uk-text-truncate" [class.uk-text-small]="smallChip">{{getLabel(chip.value)}}</span>
|
129 |
|
|
<icon name="remove_circle" class="mat-chip-remove" [flex]="true" [ratio]="smallChip?0.8:1" (click)="removed(i)"></icon>
|
130 |
|
|
</span>
|
131 |
60310
|
k.triantaf
|
</mat-chip>
|
132 |
60456
|
k.triantaf
|
<div class="uk-width-expand uk-position-relative chip-input">
|
133 |
60968
|
k.triantaf
|
<input #searchInput style="width: calc(100% - 8px) !important;" [formControl]="searchControl" [matAutocomplete]="auto"
|
134 |
60489
|
k.triantaf
|
[matChipInputFor]="chipList" [matAutocompleteConnectedTo]="origin"
|
135 |
60413
|
k.triantaf
|
[matChipInputAddOnBlur]="addExtraChips && searchControl.value"
|
136 |
|
|
(matChipInputTokenEnd)="add($event)">
|
137 |
60310
|
k.triantaf
|
<div *ngIf="placeholder && !searchControl.value" class="placeholder uk-width-1-1"
|
138 |
|
|
(click)="searchInput.focus()">{{placeholder}}</div>
|
139 |
|
|
</div>
|
140 |
60489
|
k.triantaf
|
<div class="uk-width-1-1 uk-invisible" matAutocompleteOrigin #origin="matAutocompleteOrigin"></div>
|
141 |
60310
|
k.triantaf
|
</mat-chip-list>
|
142 |
60448
|
k.triantaf
|
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)" [class]="panelClass" [panelWidth]="panelWidth">
|
143 |
61047
|
konstantin
|
<mat-option *ngFor="let option of filteredOptions | async" [value]="option.value" [attr.uk-tooltip]="option.label">
|
144 |
60310
|
k.triantaf
|
{{option.label}}
|
145 |
|
|
</mat-option>
|
146 |
|
|
</mat-autocomplete>
|
147 |
|
|
</mat-form-field>
|
148 |
|
|
</div>
|
149 |
|
|
</ng-template>
|
150 |
60568
|
k.triantaf
|
<span *ngIf="formControl.invalid && formControl.touched" class="uk-text-danger input-message">
|
151 |
|
|
<span *ngIf="formControl.errors.error">{{formControl.errors.error}}</span>
|
152 |
|
|
<span *ngIf="type === 'URL' || type === 'logoURL'">Please provide a valid URL (e.g. https://example.com)</span>
|
153 |
60585
|
k.triantaf
|
</span>
|
154 |
|
|
<span class="uk-text-danger input-message">
|
155 |
60568
|
k.triantaf
|
<ng-content select="[error]"></ng-content>
|
156 |
|
|
</span>
|
157 |
|
|
<span *ngIf="formControl.valid" class="uk-text-warning input-message">
|
158 |
|
|
<ng-content select="[warning]"></ng-content>
|
159 |
|
|
<span *ngIf="!secure">
|
160 |
|
|
<span class="uk-text-bold">Note:</span> Prefer urls like "<span class="uk-text-bold">https://</span>example.com/my-secure-image.png"
|
161 |
|
|
instead of "<span class="uk-text-bold">http://</span>example.com/my-image.png".
|
162 |
|
|
<span class="uk-text-bold">Browsers may not load non secure content.</span>
|
163 |
|
|
</span>
|
164 |
|
|
</span>
|
165 |
|
|
<span class="input-message">
|
166 |
|
|
<ng-content select="[note]"></ng-content>
|
167 |
|
|
</span>
|
168 |
59618
|
k.triantaf
|
</div>
|
169 |
|
|
</div>
|
170 |
|
|
<mat-checkbox *ngIf="type === 'checkbox'" [formControl]="formControl">{{label}}</mat-checkbox>
|
171 |
59731
|
k.triantaf
|
`,
|
172 |
|
|
styleUrls: ['input.component.css']
|
173 |
57673
|
k.triantaf
|
})
|
174 |
59618
|
k.triantaf
|
export class InputComponent implements OnInit, OnDestroy, OnChanges {
|
175 |
60413
|
k.triantaf
|
/** Basic information */
|
176 |
57768
|
k.triantaf
|
@Input('formInput') formControl: AbstractControl;
|
177 |
60665
|
k.triantaf
|
@Input('type') type: 'text' | 'URL' | 'logoURL' | 'autocomplete' | 'textarea' | 'select' | 'checkbox' | 'chips' = 'text';
|
178 |
57673
|
k.triantaf
|
@Input('label') label: string;
|
179 |
60823
|
k.triantaf
|
/** Text */
|
180 |
|
|
@ViewChild('input') input: ElementRef;
|
181 |
60568
|
k.triantaf
|
/** Textarea options */
|
182 |
57673
|
k.triantaf
|
@Input('rows') rows: number = 3;
|
183 |
60413
|
k.triantaf
|
/** Select | chips available options */
|
184 |
60968
|
k.triantaf
|
@Input('options') options: Option[] = [];
|
185 |
59618
|
k.triantaf
|
@Input('hint') hint = null;
|
186 |
|
|
@Input('placeholder') placeholder = '';
|
187 |
60413
|
k.triantaf
|
@Input() inputClass: string = 'input-box';
|
188 |
|
|
/** Extra element Right or Left of the input */
|
189 |
59618
|
k.triantaf
|
@Input() extraLeft: boolean = true;
|
190 |
60274
|
k.triantaf
|
@Input() gridSmall: boolean = false;
|
191 |
59623
|
k.triantaf
|
@Input() hideControl: boolean = false;
|
192 |
60413
|
k.triantaf
|
@Input() flex: 'middle' | 'top' | 'bottom' = 'middle';
|
193 |
|
|
/** Icon Right or Left on the input */
|
194 |
59731
|
k.triantaf
|
@Input() icon: string = null;
|
195 |
|
|
@Input() iconLeft: boolean = false;
|
196 |
60413
|
k.triantaf
|
/** Chip options */
|
197 |
60310
|
k.triantaf
|
@Input() removable: boolean = true;
|
198 |
60413
|
k.triantaf
|
@Input() addExtraChips: boolean = false;
|
199 |
60448
|
k.triantaf
|
@Input() smallChip: boolean = false;
|
200 |
|
|
@Input() panelWidth: number = 300;
|
201 |
|
|
@Input() panelClass: string = null;
|
202 |
60489
|
k.triantaf
|
@Input() showOptionsOnEmpty: boolean = true;
|
203 |
60968
|
k.triantaf
|
@Input() validators: ValidatorFn[];
|
204 |
60413
|
k.triantaf
|
@Output() focusEmitter: EventEmitter<boolean> = new EventEmitter<boolean>();
|
205 |
60568
|
k.triantaf
|
/** LogoUrl information */
|
206 |
|
|
public secure: boolean = true;
|
207 |
60413
|
k.triantaf
|
/** Internal basic information */
|
208 |
|
|
public required: boolean = false;
|
209 |
|
|
private initValue: any;
|
210 |
60674
|
k.triantaf
|
/** Chips && Autocomplete*/
|
211 |
60310
|
k.triantaf
|
public filteredOptions: Observable<Option[]>;
|
212 |
|
|
public searchControl: FormControl;
|
213 |
59618
|
k.triantaf
|
private subscriptions: any[] = [];
|
214 |
60413
|
k.triantaf
|
@ViewChild('select') select: MatSelect;
|
215 |
|
|
@ViewChild('searchInput') searchInput: ElementRef;
|
216 |
|
|
focused: boolean = false;
|
217 |
59618
|
k.triantaf
|
|
218 |
60413
|
k.triantaf
|
constructor(private elementRef: ElementRef) {
|
219 |
57673
|
k.triantaf
|
}
|
220 |
59618
|
k.triantaf
|
|
221 |
60413
|
k.triantaf
|
@HostListener('document:click', ['$event'])
|
222 |
|
|
clickOut(event) {
|
223 |
|
|
this.focused = !!this.elementRef.nativeElement.contains(event.target);
|
224 |
|
|
this.focusEmitter.emit(this.focused);
|
225 |
|
|
}
|
226 |
|
|
|
227 |
57673
|
k.triantaf
|
ngOnInit(): void {
|
228 |
59618
|
k.triantaf
|
this.reset();
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
ngOnChanges(changes: SimpleChanges) {
|
232 |
60413
|
k.triantaf
|
if (changes.formControl) {
|
233 |
59618
|
k.triantaf
|
this.reset();
|
234 |
|
|
}
|
235 |
|
|
}
|
236 |
|
|
|
237 |
60310
|
k.triantaf
|
get formAsArray(): FormArray {
|
238 |
60413
|
k.triantaf
|
return (<FormArray>this.formControl);
|
239 |
60310
|
k.triantaf
|
}
|
240 |
|
|
|
241 |
59618
|
k.triantaf
|
reset() {
|
242 |
60568
|
k.triantaf
|
this.secure = true;
|
243 |
59618
|
k.triantaf
|
this.unsubscribe();
|
244 |
57735
|
k.triantaf
|
this.initValue = HelperFunctions.copy(this.formControl.value);
|
245 |
60568
|
k.triantaf
|
if(this.type === 'logoURL') {
|
246 |
|
|
this.secure = (!this.initValue || this.initValue.includes('https://'));
|
247 |
|
|
}
|
248 |
60688
|
k.triantaf
|
if (this.type === 'chips' || this.type === 'autocomplete') {
|
249 |
60968
|
k.triantaf
|
if(this.options) {
|
250 |
60688
|
k.triantaf
|
this.filteredOptions = of(this.options);
|
251 |
60968
|
k.triantaf
|
this.searchControl = new FormControl('', this.validators);
|
252 |
60688
|
k.triantaf
|
this.subscriptions.push(this.searchControl.valueChanges.subscribe(value => {
|
253 |
|
|
setTimeout(() => {
|
254 |
|
|
this.searchInput.nativeElement.focus();
|
255 |
|
|
this.searchInput.nativeElement.value = value;
|
256 |
|
|
},0);
|
257 |
|
|
}));
|
258 |
|
|
this.filteredOptions = this.searchControl.valueChanges.pipe(startWith(''),
|
259 |
|
|
map(option => this.filter(option)));
|
260 |
|
|
}
|
261 |
60310
|
k.triantaf
|
}
|
262 |
59618
|
k.triantaf
|
if (this.formControl && this.formControl.validator) {
|
263 |
58864
|
k.triantaf
|
let validator = this.formControl.validator({} as AbstractControl);
|
264 |
|
|
this.required = (validator && validator.required);
|
265 |
|
|
}
|
266 |
59618
|
k.triantaf
|
this.subscriptions.push(this.formControl.valueChanges.subscribe(value => {
|
267 |
60413
|
k.triantaf
|
value = (value === '') ? null : value;
|
268 |
60568
|
k.triantaf
|
if(this.type === 'logoURL') {
|
269 |
|
|
this.secure = (!value || value.includes('https://'));
|
270 |
|
|
}
|
271 |
60413
|
k.triantaf
|
if (this.initValue === value || (this.initValue === '' && value === null)) {
|
272 |
57735
|
k.triantaf
|
this.formControl.markAsPristine();
|
273 |
|
|
}
|
274 |
60688
|
k.triantaf
|
if(this.searchControl) {
|
275 |
|
|
this.searchControl.setValue(null);
|
276 |
|
|
}
|
277 |
59618
|
k.triantaf
|
}));
|
278 |
|
|
if (!this.formControl.value) {
|
279 |
60953
|
k.triantaf
|
this.formControl.setValue((this.type === "checkbox")?false:'');
|
280 |
59618
|
k.triantaf
|
}
|
281 |
|
|
}
|
282 |
|
|
|
283 |
|
|
unsubscribe() {
|
284 |
|
|
this.subscriptions.forEach(subscription => {
|
285 |
60413
|
k.triantaf
|
if (subscription instanceof Subscription) {
|
286 |
59618
|
k.triantaf
|
subscription.unsubscribe();
|
287 |
|
|
}
|
288 |
57735
|
k.triantaf
|
});
|
289 |
57673
|
k.triantaf
|
}
|
290 |
59618
|
k.triantaf
|
|
291 |
|
|
openSelect() {
|
292 |
60413
|
k.triantaf
|
if (this.select) {
|
293 |
59618
|
k.triantaf
|
this.select.open();
|
294 |
|
|
}
|
295 |
|
|
}
|
296 |
|
|
|
297 |
57673
|
k.triantaf
|
ngOnDestroy(): void {
|
298 |
59618
|
k.triantaf
|
this.unsubscribe();
|
299 |
57673
|
k.triantaf
|
}
|
300 |
59618
|
k.triantaf
|
|
301 |
57708
|
k.triantaf
|
stopPropagation() {
|
302 |
59618
|
k.triantaf
|
event.stopPropagation();
|
303 |
57708
|
k.triantaf
|
}
|
304 |
60310
|
k.triantaf
|
|
305 |
|
|
removed(index: number) {
|
306 |
|
|
this.formAsArray.removeAt(index);
|
307 |
|
|
this.formAsArray.markAsDirty();
|
308 |
60413
|
k.triantaf
|
this.searchControl.setValue('');
|
309 |
|
|
this.stopPropagation();
|
310 |
60310
|
k.triantaf
|
}
|
311 |
|
|
|
312 |
|
|
selected(event: MatAutocompleteSelectedEvent): void {
|
313 |
|
|
this.formAsArray.push(new FormControl(event.option.value));
|
314 |
|
|
this.formAsArray.markAsDirty();
|
315 |
|
|
this.searchControl.setValue('');
|
316 |
60413
|
k.triantaf
|
this.stopPropagation();
|
317 |
60310
|
k.triantaf
|
}
|
318 |
|
|
|
319 |
|
|
private filter(value: string): Option[] {
|
320 |
60674
|
k.triantaf
|
let options = this.options;
|
321 |
|
|
if(this.type === "chips") {
|
322 |
60954
|
k.triantaf
|
options = options.filter(option => !this.formAsArray.value.find(value => HelperFunctions.equals(option.value, value)));
|
323 |
60310
|
k.triantaf
|
}
|
324 |
60674
|
k.triantaf
|
if ((!value || value.length == 0)) {
|
325 |
|
|
return (this.showOptionsOnEmpty)?options:[];
|
326 |
|
|
}
|
327 |
60310
|
k.triantaf
|
const filterValue = value.toString().toLowerCase();
|
328 |
|
|
return options.filter(option => option.label.toLowerCase().indexOf(filterValue) != -1);
|
329 |
|
|
}
|
330 |
60413
|
k.triantaf
|
|
331 |
|
|
add(event: MatChipInputEvent) {
|
332 |
60968
|
k.triantaf
|
if (this.addExtraChips && event.value && this.searchControl.valid) {
|
333 |
60413
|
k.triantaf
|
this.stopPropagation();
|
334 |
60968
|
k.triantaf
|
this.formAsArray.push(new FormControl(event.value, this.validators));
|
335 |
60413
|
k.triantaf
|
this.formAsArray.markAsDirty();
|
336 |
|
|
this.searchControl.setValue('');
|
337 |
|
|
this.searchInput.nativeElement.value = '';
|
338 |
|
|
}
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
getLabel(value: any) {
|
342 |
60949
|
k.triantaf
|
let option = this.options.find(option => HelperFunctions.equals(option.value, value));
|
343 |
60413
|
k.triantaf
|
return (option) ? option.label : value;
|
344 |
|
|
}
|
345 |
60674
|
k.triantaf
|
|
346 |
60688
|
k.triantaf
|
resetSearch(event: any) {
|
347 |
60674
|
k.triantaf
|
event.stopPropagation();
|
348 |
60688
|
k.triantaf
|
this.searchControl.setValue('');
|
349 |
60674
|
k.triantaf
|
this.formControl.setValue(null);
|
350 |
|
|
}
|
351 |
57673
|
k.triantaf
|
}
|