From 2e6513ed03067026c7ddf87b3dbf2dcbd43b06b8 Mon Sep 17 00:00:00 2001
From: Drew Ansbacher
- Number not in range + {{ control.errors['numberNotInRange'].value }}
{{ spec.name }} must be a number
@@ -25,7 +25,7 @@
- List not in range
+ {{ control.errors['listNotInRange'].value }}
{{ control.errors.listNotUnique.value }}
diff --git a/ui/src/app/components/form-object/form-object.component.ts b/ui/src/app/components/form-object/form-object.component.ts
index 90a381149..e08f69875 100644
--- a/ui/src/app/components/form-object/form-object.component.ts
+++ b/ui/src/app/components/form-object/form-object.component.ts
@@ -154,7 +154,6 @@ export class FormObjectComponent {
}
async presentAlertChangeWarning (key: string, spec: ValueSpec, okFn?: Function, cancelFn?: Function) {
- console.log('Here here here', spec['change-warning'])
if (!spec['change-warning'] || this.warningAck[key]) return okFn ? okFn() : null
this.warningAck[key] = true
diff --git a/ui/src/app/services/form.service.ts b/ui/src/app/services/form.service.ts
index 9fe2d458c..92c4bbf76 100644
--- a/ui/src/app/services/form.service.ts
+++ b/ui/src/app/services/form.service.ts
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'
import { AbstractControl, FormArray, FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'
-import { ConfigSpec, isValueSpecListOf, ListValueSpecNumber, ListValueSpecObject, ListValueSpecOf, ListValueSpecString, ListValueSpecUnion, UniqueBy, ValueSpec, ValueSpecEnum, ValueSpecList, ValueSpecListOf, ValueSpecNumber, ValueSpecObject, ValueSpecString, ValueSpecUnion } from '../pkg-config/config-types'
+import { ConfigSpec, isValueSpecListOf, ListValueSpecNumber, ListValueSpecObject, ListValueSpecString, ListValueSpecUnion, UniqueBy, ValueSpec, ValueSpecEnum, ValueSpecList, ValueSpecListOf, ValueSpecNumber, ValueSpecObject, ValueSpecString, ValueSpecUnion } from '../pkg-config/config-types'
import { getDefaultString, Range } from '../pkg-config/config-utilities'
const Mustache = require('mustache')
@@ -158,7 +158,7 @@ export function numberInRange (stringRange: string): ValidatorFn {
Range.from(stringRange).checkIncludes(control.value)
return null
} catch (e) {
- return { numberNotInRange: { value: control.value } }
+ return { numberNotInRange: { value: getRangeMessage(stringRange) } }
}
}
}
@@ -186,13 +186,25 @@ export function listInRange (stringRange: string): ValidatorFn {
const max = range.integralMax()
const length = control.value.length
if ((min && length < min) || (max && length > max)) {
- return { listNotInRange: { value: control.value } }
+ return { listNotInRange: { value: getRangeMessage(stringRange, true) } }
} else {
return null
}
}
}
+function getRangeMessage (stringRange: string, isList = false): string {
+ const range = Range.from(stringRange)
+ const min = range.integralMin()
+ const max = range.integralMax()
+ const messageStart = isList ? 'List length must be ' : 'Must be '
+ const minMessage = !!min ? `greater than ${min}` : ''
+ const and = !!min && !!max ? ' and ' : ''
+ const maxMessage = !!max ? `less than ${max}` : ''
+
+ return `${messageStart} ${minMessage}${and}${maxMessage}`
+}
+
export function listUnique (spec: ValueSpecList): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
for (let idx = 0; idx < control.value.length; idx++) {