Input: Show static placeholder in case of autocomplete. Update validators of form control when input validators is changed
This commit is contained in:
parent
4a03065dbd
commit
1d2a0effa8
|
@ -85,7 +85,10 @@ declare var UIkit;
|
|||
<ng-template [ngIf]="type === 'autocomplete'">
|
||||
<input *ngIf="focused" [attr.placeholder]="placeholderInfo?.static?placeholderInfo.label:hint"
|
||||
#searchInput class="input" [formControl]="searchControl" [class.uk-text-truncate]="!focused">
|
||||
<div *ngIf="!focused && !selectable" class="input uk-text-truncate">{{getLabel(formAsControl.value)}}</div>
|
||||
<ng-container *ngIf="!focused && !selectable">
|
||||
<div *ngIf="!getLabel(formControl.value)" class="input placeholder uk-text-truncate">{{placeholderInfo?.static?placeholderInfo.label:getLabel(formAsControl.value)}}</div>
|
||||
<div *ngIf="getLabel(formControl.value)" class="input uk-text-truncate">{{getLabel(formAsControl.value)}}</div>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="!focused && selectable" >
|
||||
<div *ngIf="!getLabel(formControl.value)" class="input uk-text-truncate">{{noValueSelected}}</div>
|
||||
<div *ngIf="getLabel(formControl.value)" class="input uk-text-truncate">{{getLabel(formControl.value)}}</div>
|
||||
|
@ -128,7 +131,7 @@ declare var UIkit;
|
|||
(click)="resetSearch($event)">
|
||||
<icon [flex]="true" name="close"></icon>
|
||||
</button>
|
||||
<button *ngIf="!!formControl?.value && searchable" class="uk-close uk-icon" (click)="resetValue($event)">
|
||||
<button *ngIf="!searchControl?.value && !!formControl?.value && (searchable || !selectable)" class="uk-close uk-icon" (click)="resetValue($event)">
|
||||
<icon [flex]="true" name="close"></icon>
|
||||
</button>
|
||||
</ng-template>
|
||||
|
@ -328,8 +331,7 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
this.formAsArray.push(new UntypedFormControl(value, this.validators));
|
||||
});
|
||||
} else {
|
||||
this.formControl = new UntypedFormControl(this.value);
|
||||
this.formControl.setValidators(this.validators);
|
||||
this.formControl = new UntypedFormControl(this.value, this.validators);
|
||||
}
|
||||
if (this.disabled) {
|
||||
this.formControl.disable();
|
||||
|
@ -346,6 +348,9 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
if (changes.value) {
|
||||
this.formControl.setValue(this.value);
|
||||
}
|
||||
if(changes.validators) {
|
||||
this.updateValidators();
|
||||
}
|
||||
if (changes.formControl || changes.validators || changes.options) {
|
||||
this.reset();
|
||||
}
|
||||
|
@ -446,6 +451,18 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
|
|||
});
|
||||
}
|
||||
|
||||
updateValidators() {
|
||||
if(this.formAsArray) {
|
||||
this.formAsArray.controls.forEach(control => {
|
||||
control.setValidators(this.validators);
|
||||
control.updateValueAndValidity();
|
||||
})
|
||||
} else {
|
||||
this.formControl.setValidators(this.validators);
|
||||
this.formControl.updateValueAndValidity();
|
||||
}
|
||||
}
|
||||
|
||||
remove(index: number, event) {
|
||||
if (this.focused) {
|
||||
this.formAsArray.removeAt(index);
|
||||
|
|
Loading…
Reference in New Issue