This commit is contained in:
Drew Ansbacher
2021-08-19 11:40:52 -06:00
committed by Aiden McClelland
parent 88ed581d95
commit f3190cc68f
4 changed files with 20 additions and 6 deletions

View File

@@ -119,6 +119,8 @@ export class FormService {
private numberValidators (spec: ValueSpecNumber | ListValueSpecNumber): ValidatorFn[] {
const validators: ValidatorFn[] = []
validators.push(isNumber())
if (!(spec as ValueSpecNumber).nullable) {
validators.push(Validators.required)
}
@@ -160,6 +162,14 @@ export function numberInRange (stringRange: string): ValidatorFn {
}
}
export function isNumber (): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
return control.value == Number(control.value) ?
null :
{ invalidNumber: { value: control.value } }
}
}
export function isInteger (): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
return control.value == Math.trunc(control.value) ?