From 6ced0f74cb7514e3f729fc6722d46f5cdb440997 Mon Sep 17 00:00:00 2001
From: Florent Poittevin <florent.poittevin@unige.ch>
Date: Wed, 30 Oct 2019 15:50:05 +0100
Subject: [PATCH] fix: admin user edit role doesn't put form as dirty

---
 .../admin-user-form.presentational.html       | 21 +++++++------------
 .../admin-user-form.presentational.ts         |  4 ++++
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/app/features/admin/user/components/presentationals/admin-user-form/admin-user-form.presentational.html b/src/app/features/admin/user/components/presentationals/admin-user-form/admin-user-form.presentational.html
index 148f4b1d5..96b6263b9 100644
--- a/src/app/features/admin/user/components/presentationals/admin-user-form/admin-user-form.presentational.html
+++ b/src/app/features/admin/user/components/presentationals/admin-user-form/admin-user-form.presentational.html
@@ -94,19 +94,14 @@
       <!--        <mat-error *ngFor="let error of getFormControl(formDefinition.refreshToken).errors?.errorsFromBackend">{{error}}</mat-error>-->
       <!--      </mat-form-field>-->
 
-      <div>
-        <mat-label [class.disabled]="readonly">{{'admin.user.form.roles' | translate }}</mat-label>
-        <div *ngFor="let role of getApplicationRolesNamesArray.controls">
-          <mat-checkbox [formControl]="role.get('selected')"
-                        [disabled]="readonly"
-          >
-            {{role.value.name}}
-          </mat-checkbox>
-        </div>
-        <mat-error *ngIf="getFormControl(formDefinition.applicationRoles).invalid">{{'required' | translate}}</mat-error>
-        <mat-error
-            *ngFor="let error of getFormControl(formDefinition.applicationRoles).errors?.errorsFromBackend"
-        >{{error}}</mat-error>
+      <mat-label [class.disabled]="readonly">{{'admin.user.form.roles' | translate }}</mat-label>
+      <div *ngFor="let role of getApplicationRolesNamesArray.controls">
+        <mat-checkbox (change)="updateForm()"
+                      [formControl]="role.get('selected')"
+                      [disabled]="readonly"
+        >
+          {{role.value.name}}
+        </mat-checkbox>
       </div>
     </div>
   </div>
diff --git a/src/app/features/admin/user/components/presentationals/admin-user-form/admin-user-form.presentational.ts b/src/app/features/admin/user/components/presentationals/admin-user-form/admin-user-form.presentational.ts
index 2364a7a46..ca54fa0c9 100644
--- a/src/app/features/admin/user/components/presentationals/admin-user-form/admin-user-form.presentational.ts
+++ b/src/app/features/admin/user/components/presentationals/admin-user-form/admin-user-form.presentational.ts
@@ -127,6 +127,10 @@ export class AdminUserFormPresentational extends SharedAbstractFormPresentationa
         selected: selectedRoles.some(r => r.resId === i),
       })));
   }
+
+  updateForm(): void {
+    this.form.markAsDirty();
+  }
 }
 
 class FormComponentFormDefinition extends BaseFormDefinition {
-- 
GitLab