Closed JoeKarow closed 10 months ago
Yeah we need a better way of dealing with optionals in general. Boolean fields default to "false" in the form state, and right now there's not really any way to set an type of field to be "undefined" in case the field is optional.
Some ideas:
One easy fix could be to allow toggling between JSON and form input views, then the user could just input a json object directly similar to swagger.. this would cover all cases where the user is wanting to input some null or undefined.
Also could add some toggle or something to let the dev toggle between "undefined" and "defined", but this could start making the UI get more noisy?
Would love any opinions on these approaches or others
I think option 1 would be the most straightforward (with the bonus of null
handling).
If you're looking for a quick fix on the booleans at this time, would switching to a true/false radio button set work? An optional
field would just not have any initial value set. Or a true/false/undefined set for optionals?
I just played around with the radio solution with a "true/false" field and having the default value be undefined, the dev can clear the form to get it set back to optional if needed. Seems to work pretty well
Going to go ahead and release that as a quick fix for the boolean issue, and we'll add a json entry option for other cases
When defining the input schema, optional booleans are sent to tRPC with the value of
false
rather thanundefined
. This also happens to boolean fields inside ofz.object({}).partial()