From dd7280028c40cd766d686028dce2763e79166f73 Mon Sep 17 00:00:00 2001 From: C2RLO Date: Sun, 24 Nov 2024 14:49:11 +0100 Subject: [PATCH] Enhances device form validation Adds number validation for 'y' and 'h' fields in the device edit form Updates version to 0.37.37 --- package.json | 2 +- .../devices/edit-device/edit-device.component.html | 2 +- .../components/devices/edit-device/edit-device.component.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a5f4a76..2abdf1e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "3d-inventory-angular-ui", - "version": "0.37.36", + "version": "0.37.37", "private": true, "browser": { "fs": false, diff --git a/src/app/components/devices/edit-device/edit-device.component.html b/src/app/components/devices/edit-device/edit-device.component.html index 3dac82a..c81fbce 100644 --- a/src/app/components/devices/edit-device/edit-device.component.html +++ b/src/app/components/devices/edit-device/edit-device.component.html @@ -99,7 +99,7 @@

Edit Device

placeholder="h" required [ngClass]="{ - 'is-invalid': this.x?.status !== 'VALID', + 'is-invalid': editDeviceForm.get('position')?.get('h')?.status !== 'VALID', 'is-valid': editDeviceForm.get('position')?.get('h')?.status === 'VALID', }" /> diff --git a/src/app/components/devices/edit-device/edit-device.component.ts b/src/app/components/devices/edit-device/edit-device.component.ts index fc39749..cd7df8a 100644 --- a/src/app/components/devices/edit-device/edit-device.component.ts +++ b/src/app/components/devices/edit-device/edit-device.component.ts @@ -27,7 +27,7 @@ export class DeviceEditComponent implements OnInit { // Arrow function for number validation numberValidator: ValidatorFn = (control: AbstractControl): ValidationErrors | null => { const value: number = control.value as number - if (Number.isNaN(value) || Number(value) < 0) { + if (Number.isNaN(value) || Number(value) > 100 || Number(value) < -100) { return { invalidNumber: true } } return null @@ -40,8 +40,8 @@ export class DeviceEditComponent implements OnInit { modelId: ['', Validators.required], position: this.formBulider.group({ x: [0, [Validators.required, this.numberValidator]], - y: [0, [Validators.required]], - h: [0, [Validators.required]], + y: [0, [Validators.required, this.numberValidator]], + h: [0, [Validators.required, this.numberValidator]], }), }) }