Skip to content

Commit

Permalink
fix(*): correctly display label in entity select field (#1226)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal committed Apr 26, 2022
1 parent 87f7be4 commit d7e61b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import { ConfigurableEnumDatatype } from "../../../configurable-enum/configurabl
import { FormFieldConfig } from "../../entity-form/entity-form/FormConfig";
import { ChildrenModule } from "../../../../child-dev-project/children/children.module";
import { ChildrenService } from "../../../../child-dev-project/children/children.service";
import { of, Subject } from "rxjs";
import { NEVER, of, Subject } from "rxjs";
import { AttendanceLogicalStatus } from "../../../../child-dev-project/attendance/model/attendance-status";
import { MockedTestingModule } from "../../../../utils/mocked-testing.module";
import { AbilityService } from "../../../permissions/ability/ability.service";
import { faker } from "../../../demo-data/faker";
import { StorybookBaseModule } from "../../../../utils/storybook-base.module";
import { mockEntityMapper } from "../../../entity/mock-entity-mapper-service";
import { Ability } from "@casl/ability";
import { EntityAbility } from "../../../permissions/ability/entity-ability";

const configService = new ConfigService(mockEntityMapper());
const schemaService = new EntitySchemaService();
Expand Down Expand Up @@ -59,6 +61,7 @@ export default {
faker.random.arrayElement(childGenerator.entities)
),
loadType: () => Promise.resolve(childGenerator.entities),
receiveUpdates: () => NEVER,
},
},
{ provide: EntitySchemaService, useValue: schemaService },
Expand All @@ -73,7 +76,12 @@ export default {
},
{
provide: AbilityService,
useValue: { abilityUpdateNotifier: new Subject() },
useValue: { abilityUpdated: new Subject() },
},

{
provide: EntityAbility,
useValue: new Ability([{ subject: "all", action: "manage" }]),
},
],
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<mat-form-field *ngIf="!selectedEntity || editingSelectedEntity" [formGroup]="formControl.parent">
<mat-label>{{ label }}</mat-label>
<!--
This input is need for detecting errors in the form.
The actual input used for editing is below.
-->
<input
matInput
[formControl]="formControl"
hidden
/>
<input
#inputElement
matInput
Expand All @@ -20,6 +11,15 @@
(focusin)="updateAutocomplete(inputElement.value)"
(focusout)="select(inputElement.value)"
>
<!--
This input is need for detecting errors in the form.
The actual input used for editing is below.
-->
<input
matInput
[formControl]="formControl"
hidden
/>
<mat-autocomplete
#autoSuggestions="matAutocomplete"
(optionSelected)="select($event.option.value)"
Expand All @@ -33,6 +33,7 @@
></app-display-entity>
</mat-option>
</mat-autocomplete>

<mat-error *ngIf="formControl.errors?.required" i18n="Error message for any input">
This field is required
</mat-error>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export class EditSingleEntityComponent extends EditComponent<string> {

async onInitFromDynamicConfig(config: EditPropertyConfig) {
super.onInitFromDynamicConfig(config);
this.placeholder = $localize`:Placeholder for input to set an entity|context Select User:Select ${this.label}`;
this.placeholder = $localize`:Placeholder for input to set an entity|context Select User:Select ${
config.formFieldConfig.label || config.propertySchema?.label
}`;
const entityType: string =
config.formFieldConfig.additional || config.propertySchema.additional;
this.entities = await this.entityMapperService.loadType(entityType);
Expand Down

0 comments on commit d7e61b2

Please sign in to comment.