Fixed some issues with employee-edit form

This commit is contained in:
Erik Tiekstra
2021-09-11 07:58:31 +02:00
parent 723ad02092
commit de76e95e05
2 changed files with 14 additions and 9 deletions

View File

@@ -118,8 +118,6 @@
af-variation="warning"
af-heading="Du har inte gjort några ändringar"
af-heading-level="h4"
[afCloseable]="true"
(afOnClose)="displayPristineWarning = false"
>
<p>Du har inte gjort några ändringar i formuläret. För att spara personalkontot behöver ändringar göras.</p>
</digi-notification-alert>

View File

@@ -64,12 +64,12 @@ export class EditEmployeeFormComponent implements OnInit, OnChanges {
readonly utforandeVerksamhetElementId = `utforande-verksamhet-control-${this.formUuid}`;
readonly firstValidationErrorLinkId = `validation-error-link-${this.formUuid}`;
private _submitted = false;
editEmployeeFormGroup: FormGroup | null = null;
displayEditWithoutRolesDialog = false;
displayPristineWarning = false;
displayRolesDialog = false;
displayErrorSummary = false;
selectableTjansterFormItems: Array<FormSelectItem> | null = null;
@@ -133,6 +133,13 @@ export class EditEmployeeFormComponent implements OnInit, OnChanges {
return this.editEmployeeFormGroup?.get(this.selectAllUtforandeVerksamheterFormControlName);
}
get displayPristineWarning(): boolean {
return this._submitted && this.editEmployeeFormGroup.pristine && this.editEmployeeFormGroup.valid;
}
get displayErrorSummary(): boolean {
return this._submitted && this.editEmployeeFormGroup.invalid;
}
private updateUtforandeVerksamhetStatus(): void {
if (this.availableUtforandeVerksamheter && this.availableUtforandeVerksamheter.length > 0) {
this.utforandeVerksamheterFormControl.enable();
@@ -195,16 +202,14 @@ export class EditEmployeeFormComponent implements OnInit, OnChanges {
}
onFormSubmitted(saveWithoutRoles = false): void {
this._submitted = true;
if (!this.editEmployeeFormGroup || this.isLoadingUtforandeVerksamheter) {
return;
}
this.displayPristineWarning = this.editEmployeeFormGroup.pristine;
this.editEmployeeFormGroup.markAllAsTouched();
if (this.editEmployeeFormGroup.invalid || this.editEmployeeFormGroup.pristine) {
this.displayErrorSummary = true;
if (this.editEmployeeFormGroup.invalid) {
setTimeout(() => {
this.focusLinkElement('.error-list__validation-error-link a');
});
@@ -212,7 +217,9 @@ export class EditEmployeeFormComponent implements OnInit, OnChanges {
return;
}
this.displayErrorSummary = false;
if (this.editEmployeeFormGroup.pristine) {
return;
}
const roles = this.employeeFormService.getRolesFromFormGroup(this.rolesFormGroup, this.availableRoles);