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 have a form with initial values (defaultValue) and a nested array, but the initialValue was always undefined. It took me awhile to figure out what is going on, but it appears that it was because the nested object was a class. This is a simple class with just public properties.
What I expect to work:
import{useForm}from'@conform-to/react';classTodo{id: number;title: string;constructor(id: number,title: string){this.id=id;this.title=title;}}constformDefault={todos: [newTodo(3,'do something'),newTodo(4,'do another thing'),],};exportdefaultfunctionIndex(){const[form,fields]=useForm({defaultValue: formDefault,});consttodos=fields.todos.getFieldList();return(<div><formid={form.id}><ul>{todos.map((todo)=>{consttodoFields=todo.getFieldset();return(<likey={todo.key}><inputhiddenreadOnlyname={todoFields.id.name}value={todoFields.id.initialValue}/><inputname={todoFields.title.name}defaultValue={todoFields.title.initialValue}/><div>{todoFields.title.errors}</div></li>);})}</ul></form></div>);}
In the stackblitz snippet, you can alternate between using a class and plain JavaScript objects. The location to access the id value changes between the two. It should be consistent.
What browsers are you seeing the problem on?
Chrome, Firefox
Screenshots or Videos
No response
Additional context
The actual class of values is generated for protobufjs, but I reproduced the problem with just a simple class and constructor.
The inability to proxy a class also seems to be applicable at the top level. See the ~/routes/edit.$id._index/route.tsx file in the above snippet to view that.
The text was updated successfully, but these errors were encountered:
I don't think we can support a class instance in the default value unless it is serializable (This is not implemented, just an idea). Conform does an additional normalization step to ensure that the default value can be compared with the form value for additional checks such as the dirty state. But this won't work correctly in your case.
You will need to convert it to an object literal before passing it to the default value. Conform should probably throw an error if it finds this as well.
Describe the bug and the expected behavior
I have a form with initial values (
defaultValue
) and a nested array, but theinitialValue
was alwaysundefined
. It took me awhile to figure out what is going on, but it appears that it was because the nested object was aclass
. This is a simple class with just public properties.What I expect to work:
Conform version
v1.1.0
Steps to Reproduce the Bug or Issue
View this snippet: https://stackblitz.com/edit/remix-run-remix-cym13r?file=app%2Froutes%2F_index.tsx
In the stackblitz snippet, you can alternate between using a
class
and plain JavaScript objects. The location to access theid
value changes between the two. It should be consistent.What browsers are you seeing the problem on?
Chrome, Firefox
Screenshots or Videos
No response
Additional context
The actual class of values is generated for
protobufjs
, but I reproduced the problem with just a simpleclass
andconstructor
.The inability to proxy a
class
also seems to be applicable at the top level. See the~/routes/edit.$id._index/route.tsx
file in the above snippet to view that.The text was updated successfully, but these errors were encountered: