From b00896d407b16ced3f6ed2e5cbb011d38c14b7e0 Mon Sep 17 00:00:00 2001 From: Fuzi_fauzia Date: Wed, 28 Aug 2024 15:16:05 +0700 Subject: [PATCH] validasi mandatory hari --- src/app/_layout/footer/footer.component.html | 2 +- .../control-scheduler.component.html | 4 + .../control-scheduler.component.ts | 78 ++++++++++--------- src/app/login/login.component.html | 2 +- 4 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/app/_layout/footer/footer.component.html b/src/app/_layout/footer/footer.component.html index 6a5fa9d..7e9abf0 100644 --- a/src/app/_layout/footer/footer.component.html +++ b/src/app/_layout/footer/footer.component.html @@ -13,7 +13,7 @@ href="https://allbestsistem.com/" target="_blank" style="background-color: #ffffff !important;" - >Smart Building Management Systems (V@2024-08-27.2) + >Smart Building Management Systems (V@2024-08-28.1)

diff --git a/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.html b/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.html index ee3e4af..c1c2411 100644 --- a/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.html +++ b/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.html @@ -80,7 +80,11 @@ }} +
+ Please select at least one day. +
+
diff --git a/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.ts b/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.ts index 3a50203..7c28e77 100644 --- a/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.ts +++ b/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.ts @@ -85,6 +85,7 @@ export class ControlSchedulerComponent { }); this.myForm = this.fb.group(controls); + this.myForm.setValidators(this.atLeastOneDaySelectedValidator()); } editForm() { @@ -105,6 +106,15 @@ export class ControlSchedulerComponent { }); } + atLeastOneDaySelectedValidator() { + return (formGroup: FormGroup) => { + const selectedDays = this.daysOfWeek.some( + (day) => formGroup.get(day.value)?.value + ); + return selectedDays ? null : { noDaySelected: true }; + }; + } + onDayChange(day: string, isChecked: boolean) { if (isChecked) { this.selectedDays.push(day); @@ -114,46 +124,44 @@ export class ControlSchedulerComponent { } save() { - const formValues = this.myForm.value; - - // Collect selected days' labels - const selectedDays = this.daysOfWeek - .filter((day) => formValues[day.value]) - .map((day) => day.value); - - // Construct the final output - let result = {}; - - if (this.mode === "add") { - result = { - name: formValues.name, - device_id: formValues.device_id, - timeset: formValues.timeset, - recurring: formValues.recurring, - active: formValues.active, - switch: formValues.switch, - days: selectedDays, - }; - } else { - result = { - id: this.data.id, - name: formValues.name, - device_id: formValues.device_id, - timeset: formValues.timeset, - recurring: formValues.recurring, - active: formValues.active, - switch: formValues.switch, - days: selectedDays, - }; - } - if (this.myForm.valid) { + const formValues = this.myForm.value; + + // Collect selected days' labels + const selectedDays = this.daysOfWeek + .filter((day) => formValues[day.value]) + .map((day) => day.value); + + // Construct the final output + let result = {}; + + if (this.mode === "add") { + result = { + name: formValues.name, + device_id: formValues.device_id, + timeset: formValues.timeset, + recurring: formValues.recurring, + active: formValues.active, + switch: formValues.switch, + days: selectedDays, + }; + } else { + result = { + id: this.data.id, + name: formValues.name, + device_id: formValues.device_id, + timeset: formValues.timeset, + recurring: formValues.recurring, + active: formValues.active, + switch: formValues.switch, + days: selectedDays, + }; + } + this.activeModal.close(result); } else { this.markFormGroupTouched(this.myForm); } - - // console.log("Form Result: ", result); } markFormGroupTouched(formGroup: FormGroup) { diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html index d812386..bdfb12d 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -138,7 +138,7 @@

- (v@2024.08.27.2) + (v@2024.08.28.1)