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
Custom input component receives wrong path from props and it won't work when used inside useField()
Reproduction Steps
I don't know if this is specific to the beta version of Payload since I jumped straight to it never having used the 2.0 version, but I found an error when creating a custom field that has a custom input component.
I have the following schema for a field inside a collection called pages:
If I try to pass path from props to useField(), the changed value wont persist because the path from props is not correct.
I noticed the path from props is different from the one I get if I leave path empty (If you do not provide a path or a name, this hook will look for one using the useFieldPath hook.)
From props I get: layout.text.colors.textColor
From useField() I get: layout.0.colors.textColor
Whenever I leave path empy in useField() it will persist the changes as it seems it's the correct path.
Adapters and Plugins
db-postgres
EDIT
I noticed that if this same field is nested inside a row field which shouldn't change the schema of path, I also get the correct result from getField() when I do not pass a path, but in the path from props, I get an extra dot where the field row would be in case it was another type of field, like the following: layout.text.colors..textColor
The text was updated successfully, but these errors were encountered:
The reason being on the server side we can't know exactly where your data will end up, so client hooks are safer to retrieve the path as it can change dynamically as well, eg. if you drag the blocks around.
Link to reproduction
No response
Payload Version
3.0.0-beta.34
Node Version
20.6.0
Next.js Version
14.3.0-canary.68
Describe the Bug
Custom input component receives wrong path from props and it won't work when used inside useField()
Reproduction Steps
I don't know if this is specific to the beta version of Payload since I jumped straight to it never having used the 2.0 version, but I found an error when creating a custom field that has a custom input component.
I have the following schema for a field inside a collection called pages:
And this is my component ColorsFieldInput.tsx:
If I try to pass path from props to useField(), the changed value wont persist because the path from props is not correct.
I noticed the path from props is different from the one I get if I leave path empty (If you do not provide a path or a name, this hook will look for one using the useFieldPath hook.)
From props I get:
layout.text.colors.textColor
From useField() I get:
layout.0.colors.textColor
Whenever I leave path empy in useField() it will persist the changes as it seems it's the correct path.
Adapters and Plugins
db-postgres
EDIT
I noticed that if this same field is nested inside a row field which shouldn't change the schema of path, I also get the correct result from getField() when I do not pass a path, but in the path from props, I get an extra dot where the field row would be in case it was another type of field, like the following:
layout.text.colors..textColor
The text was updated successfully, but these errors were encountered: