File tree Expand file tree Collapse file tree 2 files changed +53
-7
lines changed
trpc-ui/src/react-app/components/form/fields Expand file tree Collapse file tree 2 files changed +53
-7
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ const postsRouter = createTRPCRouter({
58
58
} ;
59
59
} ) ,
60
60
} ) ;
61
+ const discriminatedFieldEnum = z . enum ( [ "One" , "Two" ] ) ;
61
62
62
63
export const appRouter = createTRPCRouter ( {
63
64
postsRouter,
@@ -156,6 +157,26 @@ export const appRouter = createTRPCRouter({
156
157
content,
157
158
} ;
158
159
} ) ,
160
+ discriminatedUnionInput : procedure
161
+ . input (
162
+ z . object ( {
163
+ aDiscriminatedUnion : z . discriminatedUnion ( "discriminatedField" , [
164
+ z . object ( {
165
+ discriminatedField : discriminatedFieldEnum . extract ( [ "One" ] ) , // <-- this doesn't work
166
+ aFieldThatOnlyShowsWhenValueIsOne : z . string ( ) ,
167
+ } ) ,
168
+ z . object ( {
169
+ discriminatedField : z . literal ( "Two" ) ,
170
+ aFieldThatOnlyShowsWhenValueIsTwo : z . object ( {
171
+ someTextFieldInAnObject : z . string ( ) ,
172
+ } ) ,
173
+ } ) ,
174
+ ] ) ,
175
+ } ) ,
176
+ )
177
+ . query ( ( { input } ) => {
178
+ return input ;
179
+ } ) ,
159
180
procedureWithDescription : procedure
160
181
. meta ( {
161
182
description :
Original file line number Diff line number Diff line change @@ -34,12 +34,9 @@ export function ObjectField({
34
34
</ div >
35
35
) ;
36
36
}
37
- return (
38
- < InputGroupContainer
39
- title = { label }
40
- iconElement = { overrideIconElement ?? < ObjectIcon className = "mr-1" /> }
41
- >
42
- { Object . entries ( node . children ) . map ( ( [ childFieldName , e ] ) => (
37
+ const renderField = ( ) => {
38
+ try {
39
+ return Object . entries ( node . children ) . map ( ( [ childFieldName , e ] ) => (
43
40
< Field
44
41
inputNode = { {
45
42
...e ,
@@ -48,7 +45,35 @@ export function ObjectField({
48
45
control = { control }
49
46
key = { childFieldName }
50
47
/>
51
- ) ) }
48
+ ) ) ;
49
+ } catch ( e ) {
50
+ return (
51
+ < div >
52
+ < h1 className = "font-semibold text-error text-xl" >
53
+ Field Rendering Error
54
+ </ h1 >
55
+ Unfortunately, trpc-ui is unable to render the requested zod field.
56
+ Not all zod validators are fully supported.{ " " }
57
+ < a
58
+ href = "https://github.com/aidansunbury/trpc-ui/issues/new?template=bug_report.md"
59
+ target = "_blank"
60
+ rel = "noreferrer"
61
+ className = "text-blue-600 underline visited:text-purple-600"
62
+ >
63
+ open an issue ↗
64
+ </ a > { " " }
65
+ with the zod schema that caused this error so that it can be fixed.
66
+ </ div >
67
+ ) ;
68
+ }
69
+ } ;
70
+
71
+ return (
72
+ < InputGroupContainer
73
+ title = { label }
74
+ iconElement = { overrideIconElement ?? < ObjectIcon className = "mr-1" /> }
75
+ >
76
+ { renderField ( ) }
52
77
</ InputGroupContainer >
53
78
) ;
54
79
}
You can’t perform that action at this time.
0 commit comments