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 want to make a custom component for a block to select options. When editing the block, the goal is to have a Settings icon that opens a popover panel with options in that panel. In the block, I have an options group that has many fields within it. Some fields are quite simple like checkboxes that I can make on my own. One of the more complicated fields is a relationship field. The @payloadcms/ui package exports a RelationshipField component that I would love to use so I don't need to roll my own logic for fetching/filtering/displaying possible documents.
The issue I've run into is that the exported fields from the UI package don't take the passed path internally. What these fields do internally is get the path from context, but because I've set the custom component as the options group, that is the path these Fields will use. So when I select a document from the RelationshipField and try to save the document, I get an error because it's trying to set the { relationTo: COLLECTION_SLUG, value: DOCUMENT_ID } as the value of the group.
I've opened an issue here, but have since noticed it in other fields such as the CheckboxField. Because this seems to be the way these Fields work by-and-large, I'm wondering if I'm missing something or what the best way is to nest un-modified field components within my custom component?
Code for reference:
Block config group where custom component is defined:
import{blockStyling}from"./styling"import{blockVisibility}from"./blockVisibility"importtype{Field}from"payload"importtype{BlockOptions}from"~cms/types/generated"exportconstblockOptions: (defaults?: Partial<BlockOptions>)=>Field=(defaults)=>({name: "blockOptions",label: false,type: "group",interfaceName: "BlockOptions",admin: {components: {Field: "/blocks/blockOptions/styling/component"}},fields: [blockStyling(),blockVisibility,{name: "anchorId",type: "text",admin: {description:
"Add an anchor ID to this container to link to it from another part of the page."}}]})
Block Visibility group config with the relationship field:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I want to make a custom component for a block to select options. When editing the block, the goal is to have a Settings icon that opens a popover panel with options in that panel. In the block, I have an
options
group that has many fields within it. Some fields are quite simple like checkboxes that I can make on my own. One of the more complicated fields is a relationship field. The@payloadcms/ui
package exports aRelationshipField
component that I would love to use so I don't need to roll my own logic for fetching/filtering/displaying possible documents.The issue I've run into is that the exported fields from the UI package don't take the passed path internally. What these fields do internally is get the path from context, but because I've set the custom component as the
options
group, that is the path these Fields will use. So when I select a document from the RelationshipField and try to save the document, I get an error because it's trying to set the{ relationTo: COLLECTION_SLUG, value: DOCUMENT_ID }
as the value of the group.I've opened an issue here, but have since noticed it in other fields such as the CheckboxField. Because this seems to be the way these Fields work by-and-large, I'm wondering if I'm missing something or what the best way is to nest un-modified field components within my custom component?
Code for reference:
Block config group where custom component is defined:
Block Visibility group config with the relationship field:
Visibility custom component where
@payloadcms/ui
RelationshipField is used:After selecting a page from the RelationshipField dropdown and trying to save the document, this error is printed in the console:
Beta Was this translation helpful? Give feedback.
All reactions