Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ export const createMeta = <T = any>(
const nullableOrUndefined = isNullableOrUndefined(p.type)
const isRequired = !nullableOrUndefined

// check if parent is nullOr and set meta as not required
const parentNullableOrFalse = meta.nullableOrUndefined ?? false
// return a true or false
const finalIsRequired = parentNullableOrFalse ? false : isRequired

const typeToProcess = p.type
if (S.AST.isUnion(p.type)) {
// First unwrap any nested unions, then filter out null/undefined
Expand All @@ -367,7 +372,7 @@ export const createMeta = <T = any>(
const parentMeta = createMeta<T>({
parent: key,
property: p.type,
meta: { required: isRequired, nullableOrUndefined }
meta: { required: finalIsRequired, nullableOrUndefined }
})
acc[key as NestedKeyOf<T>] = parentMeta as FieldMeta
}
Expand All @@ -380,7 +385,7 @@ export const createMeta = <T = any>(
createMeta<T>({
parent: key,
propertySignatures: nonNullType.propertySignatures,
meta: { required: isRequired, nullableOrUndefined }
meta: { required: finalIsRequired, nullableOrUndefined }
})
)
}
Expand All @@ -395,7 +400,7 @@ export const createMeta = <T = any>(
type: "multiple",
members: arrayType.elements,
rest: arrayType.rest,
required: isRequired,
required: finalIsRequired,
nullableOrUndefined
} as FieldMeta

Expand Down Expand Up @@ -456,7 +461,7 @@ export const createMeta = <T = any>(
const newMeta = createMeta<T>({
parent: key,
property: p.type,
meta: { required: isRequired, nullableOrUndefined }
meta: { required: finalIsRequired, nullableOrUndefined }
})
acc[key as NestedKeyOf<T>] = newMeta as FieldMeta
}
Expand All @@ -467,7 +472,7 @@ export const createMeta = <T = any>(
createMeta<T>({
parent: key,
propertySignatures: typeToProcess.propertySignatures,
meta: { required: isRequired, nullableOrUndefined }
meta: { required: finalIsRequired, nullableOrUndefined }
})
)
} else {
Expand Down Expand Up @@ -532,7 +537,7 @@ export const createMeta = <T = any>(
type: "multiple",
members: p.type.elements,
rest: p.type.rest,
required: isRequired,
required: finalIsRequired,
nullableOrUndefined
} as FieldMeta
}
Expand All @@ -543,7 +548,7 @@ export const createMeta = <T = any>(
meta: {
// an empty string is valid for a S.String field, so we should not mark it as required
// TODO: handle this better via the createMeta minLength parsing
required: isRequired && (p.type._tag !== "StringKeyword" || getMetadataFromSchema(p.type).minLength),
required: finalIsRequired && (p.type._tag !== "StringKeyword" || getMetadataFromSchema(p.type).minLength),
nullableOrUndefined
}
})
Expand Down
3 changes: 2 additions & 1 deletion packages/vue-components/stories/OmegaForm/Union.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class B extends S.TaggedClass<B>()("B", {
const schema = S
.Struct({
title: S.String,
union: S.Union(A, B)
// testing it works! union is nullable no asterisk showed
union: S.NullOr(S.Union(A, B))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it allows null id expect also to find a select entry representing null, so you can test and confirm the null case works as expected

})

const defaultValues: typeof schema.Encoded = {
Expand Down
Loading