validasi device

This commit is contained in:
Fuzi_fauzia 2024-08-21 10:20:59 +07:00
parent f81dc7bf66
commit 04972e33b1
4 changed files with 67 additions and 49 deletions

View File

@ -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-20.2) >Smart Building Management Systems (V@2024-08-21.2)
</a></span </a></span
> >
</p> </p>

View File

@ -69,7 +69,7 @@
<div class="input-group"> <div class="input-group">
<select <select
id="categoryId" id="categoryId"
class="form-control" class="form-control custom-select"
formControlName="categoryId" formControlName="categoryId"
[ngClass]="{ [ngClass]="{
'is-invalid': submitted && f.categoryId.errors 'is-invalid': submitted && f.categoryId.errors
@ -83,15 +83,17 @@
</option> </option>
</select> </select>
</div> </div>
<small <div
class="form-text text-muted danger" *ngIf="
*ngIf="submitted && f.categoryId.errors" projectInfo.get('categoryId').invalid &&
class="invalid-feedback" projectInfo.get('categoryId').touched
"
class="text-danger"
> >
<div *ngIf="f.categoryId.errors.required"> <small class="text-danger"
Category is required >Category is required.</small
</div> >
</small> </div>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
@ -116,15 +118,17 @@
</option> </option>
</select> </select>
</div> </div>
<small <div
class="form-text text-muted danger" *ngIf="
*ngIf="submitted && f.voltageId.errors" projectInfo.get('voltageId').invalid &&
class="invalid-feedback" projectInfo.get('voltageId').touched
"
class="text-danger"
> >
<div *ngIf="f.voltageId.errors.required"> <small class="text-danger"
Voltage is required >Voltage is required.</small
</div> >
</small> </div>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
@ -270,7 +274,7 @@
class="btn btn-primary" class="btn btn-primary"
style=" style="
color: #ffffff !important; color: #ffffff !important;
background-color: #37A647 !important; background-color: #37a647 !important;
" "
(click)="saveEdit()" (click)="saveEdit()"
*ngIf="mode === 'edit'" *ngIf="mode === 'edit'"

View File

@ -253,36 +253,50 @@ export class AddEditDeviceComponent implements OnInit {
} }
saveEdit() { saveEdit() {
if (this.projectInfo.get("roomBuildingId").value) { if (this.projectInfo.valid) {
this.monitoringApiService if (this.projectInfo.get("roomBuildingId").value) {
.putDevice(this.projectInfo.value, this.deviceId) this.monitoringApiService
.subscribe((data) => { .putDevice(this.projectInfo.value, this.deviceId)
this.router.navigate(["/device"]); .subscribe((data) => {
}); this.router.navigate(["/device"]);
} else {
Swal.fire({
title: "Apakah kamu yakin?",
text: "Data lokasi device tidak dapat diubah!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, save it!",
}).then((result) => {
if (result.isConfirmed) {
this.monitoringApiService
.putDevice(this.projectInfo.value, this.deviceId)
.subscribe((data) => {
this.router.navigate(["/device"]);
});
Swal.fire({
title: "Saved!",
text: "Data berhasil disimpan.",
icon: "success",
}); });
} } else {
}); Swal.fire({
title: "Apakah kamu yakin?",
text: "Data lokasi device tidak dapat diubah!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, save it!",
}).then((result) => {
if (result.isConfirmed) {
this.monitoringApiService
.putDevice(this.projectInfo.value, this.deviceId)
.subscribe((data) => {
this.router.navigate(["/device"]);
});
Swal.fire({
title: "Saved!",
text: "Data berhasil disimpan.",
icon: "success",
});
}
});
}
} else {
this.markFormGroupTouched(this.projectInfo)
} }
}
markFormGroupTouched(formGroup: FormGroup) {
(Object as any).values(formGroup.controls).forEach((control) => {
control.markAsTouched();
if (control.controls) {
this.markFormGroupTouched(control);
}
});
} }
cancel() { cancel() {

View File

@ -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.20.2)</span> <span>(v@2024.08.21.2)</span>
</p> </p>
<!-- <div class="card-body"> <!-- <div class="card-body">
<a <a