Browse Source

Merge pull request #8264 from kalutkaz/entityAutocompleteInputFix

Fix labelText and InputText to entity autocomplete
pull/8278/head
Igor Kulikov 4 years ago
committed by GitHub
parent
commit
2f16454f23
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.html
  2. 57
      ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts

4
ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.html

@ -16,7 +16,7 @@
-->
<mat-form-field [formGroup]="selectEntityFormGroup" class="mat-block" [appearance]="appearance">
<mat-label>{{ entityText | translate }}</mat-label>
<mat-label>{{ label | translate }}</mat-label>
<input matInput type="text"
#entityInput
formControlName="entity"
@ -42,6 +42,6 @@
</mat-option>
</mat-autocomplete>
<mat-error *ngIf="selectEntityFormGroup.get('entity').hasError('required')">
{{ entityRequiredText | translate }}
{{ requiredErrorText | translate }}
</mat-error>
</mat-form-field>

57
ui-ngx/src/app/shared/components/entity/entity-autocomplete.component.ts

@ -36,10 +36,10 @@ import { AliasEntityType, EntityType } from '@shared/models/entity-type.models';
import { BaseData } from '@shared/models/base-data';
import { EntityId } from '@shared/models/id/entity-id';
import { EntityService } from '@core/http/entity.service';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { getCurrentAuthUser } from '@core/auth/auth.selectors';
import { Authority } from '@shared/models/authority.enum';
import { isEqual } from '@core/utils';
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
@Component({
selector: 'tb-entity-autocomplete',
@ -61,6 +61,22 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
entitySubtypeValue: string;
entityText: string;
noEntitiesMatchingText: string;
entityRequiredText: string;
filteredEntities: Observable<Array<BaseData<EntityId>>>;
searchText = '';
private dirty = false;
private refresh$ = new Subject<Array<BaseData<EntityId>>>();
private propagateChange = (v: any) => { };
@Input()
set entityType(entityType: EntityType) {
if (this.entityTypeValue !== entityType) {
@ -100,16 +116,12 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
@Input()
appearance: MatFormFieldAppearance = 'fill';
private requiredValue: boolean;
get required(): boolean {
return this.requiredValue;
}
@Input()
set required(value: boolean) {
this.requiredValue = coerceBooleanProperty(value);
}
@coerceBoolean()
required: boolean;
@Input()
@coerceBoolean()
disabled: boolean;
@Output()
@ -117,19 +129,20 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
@ViewChild('entityInput', {static: true}) entityInput: ElementRef;
entityText: string;
noEntitiesMatchingText: string;
entityRequiredText: string;
filteredEntities: Observable<Array<BaseData<EntityId>>>;
searchText = '';
private dirty = false;
get requiredErrorText(): string {
if (this.requiredText && this.requiredText.length) {
return this.requiredText;
}
return this.entityRequiredText;
}
private refresh$ = new Subject<Array<BaseData<EntityId>>>();
get label(): string {
if (this.labelText && this.labelText.length) {
return this.labelText;
}
return this.entityText;
}
private propagateChange = (v: any) => { };
constructor(private store: Store<AppState>,
public translate: TranslateService,
@ -249,12 +262,6 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
break;
}
}
if (this.labelText && this.labelText.length) {
this.entityText = this.labelText;
}
if (this.requiredText && this.requiredText.length) {
this.entityRequiredText = this.requiredText;
}
const currentEntity = this.getCurrentEntity();
if (currentEntity) {
const currentEntityType = currentEntity.id.entityType;

Loading…
Cancel
Save