mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
feat: better form array validation (#2821)
This commit is contained in:
@@ -1623,6 +1623,7 @@ export module Mock {
|
||||
ISB.List.text(
|
||||
{
|
||||
name: 'RPC Auth',
|
||||
minLength: 3,
|
||||
description:
|
||||
'api keys that are authorized to access your Bitcoin node.',
|
||||
},
|
||||
|
||||
@@ -55,7 +55,10 @@ export class FormService {
|
||||
|
||||
getListItem(spec: IST.ValueSpecList, entry?: any) {
|
||||
if (IST.isValueSpecListOf(spec, 'text')) {
|
||||
return this.formBuilder.control(entry, stringValidators(spec.spec))
|
||||
return this.formBuilder.control(entry, [
|
||||
...stringValidators(spec.spec),
|
||||
Validators.required,
|
||||
])
|
||||
} else if (IST.isValueSpecListOf(spec, 'object')) {
|
||||
return this.getFormGroup(spec.spec.spec, [], entry)
|
||||
}
|
||||
@@ -116,12 +119,15 @@ export class FormService {
|
||||
case 'object':
|
||||
return this.getFormGroup(spec.spec, [], currentValue)
|
||||
case 'list':
|
||||
const mapped = (
|
||||
Array.isArray(currentValue) ? currentValue : (spec.default as any[])
|
||||
).map(entry => {
|
||||
return this.getListItem(spec, entry)
|
||||
})
|
||||
return this.formBuilder.array(mapped, listValidators(spec))
|
||||
const array = Array.isArray(currentValue) ? currentValue : spec.default
|
||||
const length = Math.max(array.length, spec.minLength || 0)
|
||||
|
||||
return this.formBuilder.array(
|
||||
Array.from({ length }).map((_, index) =>
|
||||
this.getListItem(spec, array[index]),
|
||||
),
|
||||
listValidators(spec),
|
||||
)
|
||||
case 'union':
|
||||
const currentSelection = currentValue?.selection
|
||||
const isValid = !!spec.variants[currentSelection]
|
||||
|
||||
Reference in New Issue
Block a user