validasi mandatory hari

This commit is contained in:
Fuzi_fauzia 2024-08-28 15:16:05 +07:00
parent 7c443080d6
commit b00896d407
4 changed files with 49 additions and 37 deletions

View File

@ -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)
</a></span
>
</p>

View File

@ -80,7 +80,11 @@
}}</label>
</div>
</div>
<div *ngIf="myForm.hasError('noDaySelected') && myForm.touched" class="text-danger">
Please select at least one day.
</div>
</div>
<!-- Checkbox for Repeat -->
<div class="form-group col-md-12">

View File

@ -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,6 +124,7 @@ export class ControlSchedulerComponent {
}
save() {
if (this.myForm.valid) {
const formValues = this.myForm.value;
// Collect selected days' labels
@ -147,13 +158,10 @@ export class ControlSchedulerComponent {
};
}
if (this.myForm.valid) {
this.activeModal.close(result);
} else {
this.markFormGroupTouched(this.myForm);
}
// console.log("Form Result: ", result);
}
markFormGroupTouched(formGroup: FormGroup) {

View File

@ -138,7 +138,7 @@
<p
class="card-subtitle line-on-side text-muted text-center font-small-3 mx-2 my-1"
>
<span>(v@2024.08.27.2)</span>
<span>(v@2024.08.28.1)</span>
</p>
<!-- <div class="card-body">
<a