-
-
Notifications
You must be signed in to change notification settings - Fork 7
Description
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:
- Is
form.Input name="myField._tag"recognizing thatmyFieldisNullOr? - Is it how
omegaInputreads._tag( I’m more with this ) orS.Union? - 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