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