better change warnings

This commit is contained in:
Matt Hill
2021-08-19 13:48:17 -06:00
committed by Aiden McClelland
parent 1eeb5e03ea
commit 2475c08648
5 changed files with 54 additions and 19 deletions

View File

@@ -1102,7 +1102,7 @@ export module Mock {
},
'default': 'null',
'description': 'This is not even real.',
'change-warning': 'Be careful chnaging this!',
'change-warning': 'Be careful changing this!',
'values': [
'null',
'option1',

View File

@@ -153,6 +153,7 @@ function isFullUnion (spec: ValueSpecUnion | ListValueSpecUnion): spec is ValueS
export function numberInRange (stringRange: string): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
if (!control.value) return null
try {
Range.from(stringRange).checkIncludes(control.value)
return null
@@ -164,15 +165,15 @@ export function numberInRange (stringRange: string): ValidatorFn {
export function isNumber (): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
return control.value == Number(control.value) ?
return !control.value || control.value == Number(control.value) ?
null :
{ invalidNumber: { value: control.value } }
{ notNumber: { value: control.value } }
}
}
export function isInteger (): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
return control.value == Math.trunc(control.value) ?
return !control.value || control.value == Math.trunc(control.value) ?
null :
{ numberNotInteger: { value: control.value } }
}