You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am creating some dynamic fields in my form using the form.insert method, but noticed that I was getting a type error whilst trying to add some default values. It would appear that when the field is an array and is optional/nullable then the defaultValue type becomes a string. Here is a simplified example
exportconstschema=z.object({test: z.array(z.object({nested: z.string()})).nullable()// or .optional()})
<button{...form.insert.getButtonProps({name: fields.test.name,defaultValue: {// <-- Type '{ nested: string; }' is not assignable to type 'string'.nested: "I am nested",},})}>Clickme</button>
It's fairly easy to work aroud this situation by making the field required and setting the default value of the form to an empty array, however, I thought I would report in case this was not deliberate!
Maintaining the type inside of the array would make the most sense.
Conform version
v1.0.3
Steps to Reproduce the Bug or Issue
Create a simple schema with an an optional/nullable array as a field.
Use the field metadata to insert values in the array.
See defaultValue is types as a string and not the type within the schema.
What browsers are you seeing the problem on?
Chrome, Firefox, Safari
Screenshots or Videos
No response
Additional context
No response
The text was updated successfully, but these errors were encountered:
@edmundhung this seems to be related to the defaultValue fix that @aaronadamsCA did whenever a schema has a key that is an array that also has an optional() or nullable() this seems to still have an issue.
Describe the bug and the expected behavior
I am creating some dynamic fields in my form using the
form.insert
method, but noticed that I was getting a type error whilst trying to add some default values. It would appear that when the field is an array and is optional/nullable then thedefaultValue
type becomes a string. Here is a simplified exampleIt's fairly easy to work aroud this situation by making the field required and setting the default value of the form to an empty array, however, I thought I would report in case this was not deliberate!
Maintaining the type inside of the array would make the most sense.
Conform version
v1.0.3
Steps to Reproduce the Bug or Issue
What browsers are you seeing the problem on?
Chrome, Firefox, Safari
Screenshots or Videos
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: