mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
fix: properly handle values in unions (#2826)
This commit is contained in:
@@ -37,18 +37,14 @@ export class FormService {
|
||||
}
|
||||
}
|
||||
|
||||
getUnionObject(
|
||||
spec: IST.ValueSpecUnion,
|
||||
selected: string | null,
|
||||
): UntypedFormGroup {
|
||||
const group = this.getFormGroup({
|
||||
selection: this.getUnionSelectSpec(spec, selected),
|
||||
})
|
||||
getUnionObject(spec: IST.ValueSpecUnion, value: any): UntypedFormGroup {
|
||||
const valid = spec.variants[value?.selection]
|
||||
const selected = valid ? value?.selection : spec.default
|
||||
const selection = this.getUnionSelectSpec(spec, selected)
|
||||
const group = this.getFormGroup({ selection })
|
||||
const control = selected ? spec.variants[selected].spec : {}
|
||||
|
||||
group.setControl(
|
||||
'value',
|
||||
this.getFormGroup(selected ? spec.variants[selected].spec : {}),
|
||||
)
|
||||
group.setControl('value', this.getFormGroup(control, [], value?.value))
|
||||
|
||||
return group
|
||||
}
|
||||
@@ -134,13 +130,7 @@ export class FormService {
|
||||
fileValidators(spec),
|
||||
)
|
||||
case 'union':
|
||||
const currentSelection = currentValue?.selection
|
||||
const isValid = !!spec.variants[currentSelection]
|
||||
|
||||
return this.getUnionObject(
|
||||
spec,
|
||||
isValid ? currentSelection : spec.default,
|
||||
)
|
||||
return this.getUnionObject(spec, currentValue)
|
||||
case 'toggle':
|
||||
value = currentValue === undefined ? spec.default : currentValue
|
||||
return this.formBuilder.control(value)
|
||||
|
||||
Reference in New Issue
Block a user