mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 06:19:44 +00:00
files for config
This commit is contained in:
committed by
Aiden McClelland
parent
e76ccba2f7
commit
dacd5d3e6b
@@ -18,6 +18,7 @@ import {
|
||||
UniqueBy,
|
||||
ValueSpec,
|
||||
ValueSpecEnum,
|
||||
ValueSpecFile,
|
||||
ValueSpecList,
|
||||
ValueSpecNumber,
|
||||
ValueSpecObject,
|
||||
@@ -102,31 +103,33 @@ export class FormService {
|
||||
let value: any
|
||||
switch (spec.type) {
|
||||
case 'string':
|
||||
validators = stringValidators(spec)
|
||||
if (currentValue !== undefined) {
|
||||
value = currentValue
|
||||
} else {
|
||||
value = spec.default ? getDefaultString(spec.default) : null
|
||||
}
|
||||
return this.formBuilder.control(value, validators)
|
||||
return this.formBuilder.control(value, stringValidators(spec))
|
||||
case 'number':
|
||||
validators = numberValidators(spec)
|
||||
if (currentValue !== undefined) {
|
||||
value = currentValue
|
||||
} else {
|
||||
value = spec.default || null
|
||||
}
|
||||
return this.formBuilder.control(value, validators)
|
||||
return this.formBuilder.control(value, numberValidators(spec))
|
||||
case 'object':
|
||||
return this.getFormGroup(spec.spec, [], currentValue)
|
||||
case 'list':
|
||||
validators = listValidators(spec)
|
||||
const mapped = (
|
||||
Array.isArray(currentValue) ? currentValue : (spec.default as any[])
|
||||
).map(entry => {
|
||||
return this.getListItem(spec, entry)
|
||||
})
|
||||
return this.formBuilder.array(mapped, validators)
|
||||
return this.formBuilder.array(mapped, listValidators(spec))
|
||||
case 'file':
|
||||
return this.formBuilder.control(
|
||||
currentValue || null,
|
||||
fileValidators(spec),
|
||||
)
|
||||
case 'union':
|
||||
const currentSelection = currentValue?.[spec.tag.id]
|
||||
const isValid = !!spec.variants[currentSelection]
|
||||
@@ -204,6 +207,16 @@ function listValidators(spec: ValueSpecList): ValidatorFn[] {
|
||||
return validators
|
||||
}
|
||||
|
||||
function fileValidators(spec: ValueSpecFile): ValidatorFn[] {
|
||||
const validators: ValidatorFn[] = []
|
||||
|
||||
if (!spec.nullable) {
|
||||
validators.push(Validators.required)
|
||||
}
|
||||
|
||||
return validators
|
||||
}
|
||||
|
||||
export function numberInRange(stringRange: string): ValidatorFn {
|
||||
return control => {
|
||||
const value = control.value
|
||||
|
||||
Reference in New Issue
Block a user