Skip to content

Asterisk Appears on Nullable Union _Tag Field in Form Input #473

@MindfulLearner

Description

@MindfulLearner

Mentioned in: https://discord.com/channels/1083767712431480922/1430698262985441321

Field shows asterisk (*) even when parent Union is NullOr _tag

Problem

When a parent field is S.NullOr(S.Union(...)), it still shows the required asterisk ( picture attached )

E.g.

Schema:

const myField = S.NullOr(S.Union(TypeA, TypeB))

Form:

<form.Input name="myField._tag" type="Select" />

Expected: No asterisk
Actual: Shows asterisk (*)

Questions:

  1. Is form.Input name="myField._tag" recognizing that myField is NullOr?
  2. Is it how omegaInput reads ._tag ( I’m more with this ) or S.Union?
  3. I think it’s possibly type="select" not handling this correctly?

**FROM MY INVESTIGATION **it seems to be related to ._tag,
because I tested form.Input using just myField with type=text, and the asterisk doesn’t appear. because myField is nullOr

File responsible?:
In libs from OmegaInternalInput that gives isRequired? that gives * from the file: OmegaFormStuff.ts, line 307 createMeta() lambda (maybe). When processing the Union ._tags, the nullable state from the parent is not inherited.

Fix


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

PR: #472

Real Case
costOfTravel._tag shows an asterisk even though costOfTravel: S.NullOr(CostOfTravel).withDefault.
The issue seems to be that ._tag fields are not processed correctly when their parent Union is nullable.

Remarks

Honestly, I tried to make the change, but I don’t know if it’s correct or if it really works i tried in storybook, technically working.. I tested with and withouth S.NullOr

To refine since i think these changes touches other Union type

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions