Revision 60968
Added by Konstantinos Triantafyllou over 2 years ago
input.component.ts | ||
---|---|---|
11 | 11 |
SimpleChanges, |
12 | 12 |
ViewChild |
13 | 13 |
} from "@angular/core"; |
14 |
import {AbstractControl, FormArray, FormControl} from "@angular/forms"; |
|
14 |
import {AbstractControl, FormArray, FormControl, ValidatorFn} from "@angular/forms";
|
|
15 | 15 |
import {HelperFunctions} from "../../utils/HelperFunctions.class"; |
16 | 16 |
import {Observable, of, Subscription} from "rxjs"; |
17 | 17 |
import {MatSelect} from "@angular/material/select"; |
... | ... | |
100 | 100 |
</span> |
101 | 101 |
</mat-chip> |
102 | 102 |
<div [class.uk-hidden]="formControl.value" class="uk-width-expand uk-position-relative chip-input"> |
103 |
<input #searchInput class="uk-width-1-1" [formControl]="searchControl" [matAutocomplete]="auto"
|
|
103 |
<input #searchInput [formControl]="searchControl" [matAutocomplete]="auto" |
|
104 | 104 |
[matChipInputFor]="chipList" [matAutocompleteConnectedTo]="origin"> |
105 | 105 |
<div *ngIf="placeholder && !searchInput.value" class="placeholder uk-width-1-1" |
106 | 106 |
(click)="searchInput.focus()">{{placeholder}}</div> |
... | ... | |
119 | 119 |
<div [ngClass]="inputClass" |
120 | 120 |
[attr.uk-tooltip]="formControl.disabled?'title: This field is not editable; pos: bottom-left':null" |
121 | 121 |
[class.clickable]="formControl.enabled" |
122 |
[class.uk-form-danger]="formControl.invalid && formControl.touched" (click)="openSelect()">
|
|
122 |
[class.uk-form-danger]="formControl.invalid && searchControl.invalid && searchControl.touched" (click)="openSelect()">
|
|
123 | 123 |
<mat-form-field class="uk-width-1-1"> |
124 | 124 |
<mat-chip-list #chipList> |
125 | 125 |
<mat-chip *ngFor="let chip of formAsArray.controls; let i=index" [selectable]="false" |
... | ... | |
130 | 130 |
</span> |
131 | 131 |
</mat-chip> |
132 | 132 |
<div class="uk-width-expand uk-position-relative chip-input"> |
133 |
<input #searchInput class="uk-width-1-1" [formControl]="searchControl" [matAutocomplete]="auto"
|
|
133 |
<input #searchInput style="width: calc(100% - 8px) !important;" [formControl]="searchControl" [matAutocomplete]="auto"
|
|
134 | 134 |
[matChipInputFor]="chipList" [matAutocompleteConnectedTo]="origin" |
135 | 135 |
[matChipInputAddOnBlur]="addExtraChips && searchControl.value" |
136 | 136 |
(matChipInputTokenEnd)="add($event)"> |
... | ... | |
181 | 181 |
/** Textarea options */ |
182 | 182 |
@Input('rows') rows: number = 3; |
183 | 183 |
/** Select | chips available options */ |
184 |
@Input('options') options: Option[]; |
|
184 |
@Input('options') options: Option[] = [];
|
|
185 | 185 |
@Input('hint') hint = null; |
186 | 186 |
@Input('placeholder') placeholder = ''; |
187 | 187 |
@Input() inputClass: string = 'input-box'; |
... | ... | |
200 | 200 |
@Input() panelWidth: number = 300; |
201 | 201 |
@Input() panelClass: string = null; |
202 | 202 |
@Input() showOptionsOnEmpty: boolean = true; |
203 |
@Input() validators: ValidatorFn[]; |
|
203 | 204 |
@Output() focusEmitter: EventEmitter<boolean> = new EventEmitter<boolean>(); |
204 | 205 |
/** LogoUrl information */ |
205 | 206 |
public secure: boolean = true; |
... | ... | |
248 | 249 |
this.secure = (!this.initValue || this.initValue.includes('https://')); |
249 | 250 |
} |
250 | 251 |
if (this.type === 'chips' || this.type === 'autocomplete') { |
251 |
if(!this.options) { |
|
252 |
console.error('Please provide options to continue'); |
|
253 |
} else { |
|
252 |
if(this.options) { |
|
254 | 253 |
this.filteredOptions = of(this.options); |
255 |
this.searchControl = new FormControl(''); |
|
254 |
this.searchControl = new FormControl('', this.validators);
|
|
256 | 255 |
this.subscriptions.push(this.searchControl.valueChanges.subscribe(value => { |
257 | 256 |
setTimeout(() => { |
258 | 257 |
this.searchInput.nativeElement.focus(); |
... | ... | |
333 | 332 |
} |
334 | 333 |
|
335 | 334 |
add(event: MatChipInputEvent) { |
336 |
if (this.addExtraChips && event.value) { |
|
335 |
if (this.addExtraChips && event.value && this.searchControl.valid) {
|
|
337 | 336 |
this.stopPropagation(); |
338 |
this.formAsArray.push(new FormControl(event.value)); |
|
337 |
this.formAsArray.push(new FormControl(event.value, this.validators));
|
|
339 | 338 |
this.formAsArray.markAsDirty(); |
340 | 339 |
this.searchControl.setValue(''); |
341 | 340 |
this.searchInput.nativeElement.value = ''; |
Also available in: Unified diff
[Library | Trunk]: Fix server errors. Input add validators for chips. Subscriber-invite: Change To field to chips, add short view