WEB-172 Merging all changes from main branch into dev branch (#2450)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { AbstractControl, ValidatorFn } from '@angular/forms';
|
||||
|
||||
export function maxNumberValueValidator(maxControlName: string): ValidatorFn {
|
||||
return (control: AbstractControl): { [key: string]: any } | null => {
|
||||
const maxControl = control.parent?.get(maxControlName);
|
||||
if (!maxControl || !control.value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let maxValue = maxControl.value;
|
||||
if (typeof maxValue === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
if (typeof maxValue !== 'number') {
|
||||
maxValue = maxValue * 1;
|
||||
}
|
||||
let controlValue = control.value;
|
||||
if (typeof controlValue !== 'number') {
|
||||
controlValue = controlValue * 1;
|
||||
}
|
||||
if (controlValue > maxValue) {
|
||||
return { maxValue: { requiredMax: maxValue, actual: controlValue } };
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { AbstractControl, ValidatorFn } from '@angular/forms';
|
||||
|
||||
export function minNumberValueValidator(minControlName: string): ValidatorFn {
|
||||
return (control: AbstractControl): { [key: string]: any } | null => {
|
||||
const minControl = control.parent?.get(minControlName);
|
||||
if (!minControl || !control.value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let minValue = minControl.value;
|
||||
if (typeof minValue === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
if (typeof minValue !== 'number') {
|
||||
minValue = minValue * 1;
|
||||
}
|
||||
let controlValue = control.value;
|
||||
if (typeof controlValue !== 'number') {
|
||||
controlValue = controlValue * 1;
|
||||
}
|
||||
if (controlValue < minValue) {
|
||||
return { minValue: { requiredMin: minValue, actual: controlValue } };
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user