OK-489 Formvalidation one or more persons selected
diff --git a/src/app/dialogs/shift-change/shift-change.component.html b/src/app/dialogs/shift-change/shift-change.component.html
index 1fd6202..d3d36a5 100644
--- a/src/app/dialogs/shift-change/shift-change.component.html
+++ b/src/app/dialogs/shift-change/shift-change.component.html
@@ -21,7 +21,7 @@
<multiselect class="customMultiSelect" [data]="allUsersButLoggedIn" [(ngModel)]="preSelectedUsers" [settings]="dropdownSettings"
ngDefaultControl></multiselect>
</div>
- <form #shiftForm="ngForm" ngDefaultControl>
+ <form #shiftForm="ngForm" novalidate>
<div class="panel-body">
<fieldset [disabled]="!preSelectedUsers || preSelectedUsers.length===0">
<table class="table table-bordered responsibility-column-striped">
@@ -39,8 +39,9 @@
<td class="shc-table-col">{{ responsibilityContainer.gridTerritoryDescription }}</td>
<td class="shc-table-col">
<div class="form-group">
- <select [required]="true" [(ngModel)]="getResponsiblity(responsibilityContainer,'S').newResponsibleUser" *ngIf="responsibilityContainer && getResponsiblity(responsibilityContainer,'S')"
- style="height:30px !important" class="form-control shc-table-select" name="'responsibleUserSelectionS_{{getResponsiblity(responsibilityContainer,'S').id}}'">
+ <select [(ngModel)]="getResponsiblity(responsibilityContainer,'S').newResponsibleUser" *ngIf="responsibilityContainer && getResponsiblity(responsibilityContainer,'S')"
+ style="height:30px !important" class="form-control shc-table-select" name="'responsibleUserSelectionS_{{getResponsiblity(responsibilityContainer,'S').id}}'"
+ (change)="checkIfPersonSelected()">
<option></option>
<option *ngFor="let user of preSelectedUsers" value="{{user.username}}">{{user.itemName}}</option>
</select>
@@ -48,8 +49,9 @@
</td>
<td class="shc-table-col">
<div class="form-group">
- <select [required]="true" [(ngModel)]="getResponsiblity(responsibilityContainer,'G').newResponsibleUser" *ngIf="responsibilityContainer && getResponsiblity(responsibilityContainer,'G')"
- style="height:30px !important" class="form-control shc-table-select" name="'responsibleUserSelectionG_{{getResponsiblity(responsibilityContainer,'G').id}}'">
+ <select [(ngModel)]="getResponsiblity(responsibilityContainer,'G').newResponsibleUser" *ngIf="responsibilityContainer && getResponsiblity(responsibilityContainer,'G')"
+ style="height:30px !important" class="form-control shc-table-select" name="'responsibleUserSelectionG_{{getResponsiblity(responsibilityContainer,'G').id}}'"
+ (change)="checkIfPersonSelected()">
<option></option>
<option *ngFor="let user of preSelectedUsers" value="{{user.username}}">{{user.itemName}}</option>
</select>
@@ -57,8 +59,9 @@
</td>
<td class="shc-table-col">
<div class="form-group">
- <select [required]="true" [(ngModel)]="getResponsiblity(responsibilityContainer,'F').newResponsibleUser" *ngIf="responsibilityContainer && getResponsiblity(responsibilityContainer,'F')"
- style="height:30px !important" class="form-control shc-table-select" name="'responsibleUserSelectionF_{{getResponsiblity(responsibilityContainer,'F').id}}'">
+ <select [(ngModel)]="getResponsiblity(responsibilityContainer,'F').newResponsibleUser" *ngIf="responsibilityContainer && getResponsiblity(responsibilityContainer,'F')"
+ style="height:30px !important" class="form-control shc-table-select" name="'responsibleUserSelectionF_{{getResponsiblity(responsibilityContainer,'F').id}}'"
+ (change)="checkIfPersonSelected()">
<option></option>
<option *ngFor="let user of preSelectedUsers" value="{{user.username}}" >{{user.itemName}}</option>
</select>
@@ -66,8 +69,9 @@
</td>
<td class="shc-table-col">
<div class="form-group">
- <select [required]="true" [(ngModel)]="getResponsiblity(responsibilityContainer,'W').newResponsibleUser" *ngIf="responsibilityContainer && getResponsiblity(responsibilityContainer,'W')"
- style="height:30px !important" class="form-control shc-table-select" name="'responsibleUserSelectionW_{{getResponsiblity(responsibilityContainer,'W').id}}'">
+ <select [(ngModel)]="getResponsiblity(responsibilityContainer,'W').newResponsibleUser" *ngIf="responsibilityContainer && getResponsiblity(responsibilityContainer,'W')"
+ style="height:30px !important" class="form-control shc-table-select" name="'responsibleUserSelectionW_{{getResponsiblity(responsibilityContainer,'W').id}}'"
+ (change)="checkIfPersonSelected()">
<option></option>
<option *ngFor="let user of preSelectedUsers" value="{{user.username}}" >{{user.itemName}}</option>
</select>
@@ -82,8 +86,8 @@
</div>
</div>
<div class="margin-top">
- <button class="btn btn-primary btn-sm" [disabled]="!shiftForm.form.valid" (click)="shiftChange()" autofocus>Übergeben</button>
- <button class="btn btn-primary btn-sm" [disabled]="!shiftForm.form.valid" (click)="cancelChange()" autofocus>Stornieren</button>
+ <button class="btn btn-primary btn-sm" [disabled]="shiftChangeFormInValid" (click)="shiftChange(true)" autofocus>Übergeben</button>
+ <button class="btn btn-primary btn-sm" (click)="cancelChange()" autofocus>Stornieren</button>
<button class="btn btn-primary btn-sm " (click)="dialogRef.close()">Abbrechen</button>
</div>
</div>
\ No newline at end of file
diff --git a/src/app/dialogs/shift-change/shift-change.component.ts b/src/app/dialogs/shift-change/shift-change.component.ts
index 23cde1c..278f8dc 100644
--- a/src/app/dialogs/shift-change/shift-change.component.ts
+++ b/src/app/dialogs/shift-change/shift-change.component.ts
@@ -26,6 +26,7 @@
selectAll = false;
isChangingShift = false;
noUserSelected = true;
+ shiftChangeFormInValid = true;
dropdownSettings = {};
@@ -48,6 +49,7 @@
classes: 'custom-drop-down',
badgeShowLimit: 2
};
+ this.checkIfPersonSelected();
}
getResponsibilities(): void {
@@ -69,7 +71,7 @@
}
}
}
- self.responsibilityContainers = resps;
+ self.responsibilityContainers = resps;
}
}
@@ -120,12 +122,16 @@
responsibility.newResponsibleUser = '';
}
}
- this.shiftChange();
+ this.shiftChange(false);
}
- shiftChange(): void {
+ shiftChange(filter: boolean): void {
const self = this;
- const filteredResponsibilityContainers = this.filterToValidResponsibilityContainerValues(this.responsibilityContainers);
+ let filteredResponsibilityContainers = this.responsibilityContainers;
+ if (filter) {
+ filteredResponsibilityContainers = this.filterToValidResponsibilityContainerValues(this.responsibilityContainers);
+ }
+
this.responsibilityService.planResponsibilities(filteredResponsibilityContainers).subscribe(resps => setResp(resps),
error => {
@@ -167,4 +173,16 @@
return filteredRespContainers;
}
+
+ checkIfPersonSelected() {
+ this.shiftChangeFormInValid = true;
+ for (const responsibilityContainer of this.responsibilityContainers) {
+ for (const responsibility of responsibilityContainer.responsibilityList) {
+ if (responsibility.newResponsibleUser !== '') {
+ this.shiftChangeFormInValid = false;
+ break;
+ }
+ }
+ }
+ }
}