From 71fafb46994ca22578d526e9c18f641b73d14822 Mon Sep 17 00:00:00 2001 From: MindfulLearner Date: Thu, 23 Oct 2025 01:22:59 +0200 Subject: [PATCH] test clear it works --- .../components/OmegaForm/OmegaFormStuff.ts | 19 ++++++++++++------- .../stories/OmegaForm/Union.vue | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts b/packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts index 8831cbbba..c450ffb71 100644 --- a/packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts +++ b/packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts @@ -331,6 +331,11 @@ export const createMeta = ( 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)) { const nonNullTypes = p @@ -352,7 +357,7 @@ export const createMeta = ( const parentMeta = createMeta({ parent: key, property: p.type, - meta: { required: isRequired, nullableOrUndefined } + meta: { required: finalIsRequired, nullableOrUndefined } }) acc[key as NestedKeyOf] = parentMeta as FieldMeta } @@ -365,7 +370,7 @@ export const createMeta = ( createMeta({ parent: key, propertySignatures: nonNullType.propertySignatures, - meta: { required: isRequired, nullableOrUndefined } + meta: { required: finalIsRequired, nullableOrUndefined } }) ) } @@ -380,7 +385,7 @@ export const createMeta = ( type: "multiple", members: arrayType.elements, rest: arrayType.rest, - required: isRequired, + required: finalIsRequired, nullableOrUndefined } as FieldMeta @@ -441,7 +446,7 @@ export const createMeta = ( const newMeta = createMeta({ parent: key, property: p.type, - meta: { required: isRequired, nullableOrUndefined } + meta: { required: finalIsRequired, nullableOrUndefined } }) acc[key as NestedKeyOf] = newMeta as FieldMeta } @@ -452,7 +457,7 @@ export const createMeta = ( createMeta({ parent: key, propertySignatures: typeToProcess.propertySignatures, - meta: { required: isRequired, nullableOrUndefined } + meta: { required: finalIsRequired, nullableOrUndefined } }) ) } else { @@ -517,7 +522,7 @@ export const createMeta = ( type: "multiple", members: p.type.elements, rest: p.type.rest, - required: isRequired, + required: finalIsRequired, nullableOrUndefined } as FieldMeta } @@ -528,7 +533,7 @@ export const createMeta = ( 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 } }) diff --git a/packages/vue-components/stories/OmegaForm/Union.vue b/packages/vue-components/stories/OmegaForm/Union.vue index 927381947..1061b4251 100644 --- a/packages/vue-components/stories/OmegaForm/Union.vue +++ b/packages/vue-components/stories/OmegaForm/Union.vue @@ -46,7 +46,8 @@ class B extends S.TaggedClass()("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)) }) const defaultValues: typeof schema.Encoded = {