validasi mandatory hari
This commit is contained in:
parent
7c443080d6
commit
b00896d407
|
@ -13,7 +13,7 @@
|
||||||
href="https://allbestsistem.com/"
|
href="https://allbestsistem.com/"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
style="background-color: #ffffff !important;"
|
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
|
</a></span
|
||||||
>
|
>
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -80,7 +80,11 @@
|
||||||
}}</label>
|
}}</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div *ngIf="myForm.hasError('noDaySelected') && myForm.touched" class="text-danger">
|
||||||
|
Please select at least one day.
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Checkbox for Repeat -->
|
<!-- Checkbox for Repeat -->
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
|
|
|
@ -85,6 +85,7 @@ export class ControlSchedulerComponent {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.myForm = this.fb.group(controls);
|
this.myForm = this.fb.group(controls);
|
||||||
|
this.myForm.setValidators(this.atLeastOneDaySelectedValidator());
|
||||||
}
|
}
|
||||||
|
|
||||||
editForm() {
|
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) {
|
onDayChange(day: string, isChecked: boolean) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
this.selectedDays.push(day);
|
this.selectedDays.push(day);
|
||||||
|
@ -114,6 +124,7 @@ export class ControlSchedulerComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
save() {
|
||||||
|
if (this.myForm.valid) {
|
||||||
const formValues = this.myForm.value;
|
const formValues = this.myForm.value;
|
||||||
|
|
||||||
// Collect selected days' labels
|
// Collect selected days' labels
|
||||||
|
@ -147,13 +158,10 @@ export class ControlSchedulerComponent {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.myForm.valid) {
|
|
||||||
this.activeModal.close(result);
|
this.activeModal.close(result);
|
||||||
} else {
|
} else {
|
||||||
this.markFormGroupTouched(this.myForm);
|
this.markFormGroupTouched(this.myForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log("Form Result: ", result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
markFormGroupTouched(formGroup: FormGroup) {
|
markFormGroupTouched(formGroup: FormGroup) {
|
||||||
|
|
|
@ -138,7 +138,7 @@
|
||||||
<p
|
<p
|
||||||
class="card-subtitle line-on-side text-muted text-center font-small-3 mx-2 my-1"
|
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>
|
</p>
|
||||||
<!-- <div class="card-body">
|
<!-- <div class="card-body">
|
||||||
<a
|
<a
|
||||||
|
|
Loading…
Reference in New Issue