Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Relationship fields expects ID instead of object in localized LexicalEditor #14212

Pathius started this conversation in General
Discussion options

In our situation we have this richText field

export const introductionField = (config: Config): Field => {
	return {
		name: 'introduction',
		type: 'richText',
		localized: true,
		required: config.required,
		admin: { description: 'Introduction text for the page' },
		editor: richTextEditorConfig(),
	};
};

Coming along this custom LexicalEditor

import type { LexicalEditorProps } from '@payloadcms/richtext-lexical';
import {
	BlocksFeature,
	FixedToolbarFeature,
	InlineToolbarFeature,
	lexicalEditor,
	LinkFeature,
	RelationshipFeature,
} from '@payloadcms/richtext-lexical';
import { ALL_PAGE_COLLECTIONS } from '~/fields/pageType/pageType';
import { getTranslatedLabel } from '~/utilities/getTranslatedLabel';
export const richTextEditorConfig = (config?: Partial<LexicalEditorProps>) =>
	lexicalEditor({
		features: ({ defaultFeatures }) => [
			...defaultFeatures,
			LinkFeature({
				enabledCollections: ALL_PAGE_COLLECTIONS,
				fields: ({ defaultFields }) => defaultFields,
			}),
			RelationshipFeature({
				enabledCollections: ALL_PAGE_COLLECTIONS,
			}),
			BlocksFeature({
				blocks: [
					{
						slug: 'code',
						interfaceName: 'CodeBlock',
						labels: {
							singular: getTranslatedLabel('fieldLabels:codeBlock'),
							plural: getTranslatedLabel('fieldLabels:codeBlocks'),
						},
						fields: [
							{
								name: 'code',
								type: 'code',
								label: getTranslatedLabel('fieldLabels:code'),
								required: true,
								admin: {
									language: 'javascript',
								},
							},
							{
								name: 'language',
								type: 'select',
								label: getTranslatedLabel('fieldLabels:language'),
								defaultValue: 'html',
								options: [
									{ label: 'HTML', value: 'html' },
									{ label: 'JavaScript', value: 'javascript' },
									{ label: 'TypeScript', value: 'typescript' },
									{ label: 'CSS', value: 'css' },
									{ label: 'JSON', value: 'json' },
									{ label: 'Python', value: 'python' },
									{ label: 'SQL', value: 'sql' },
									{ label: 'Shell', value: 'shell' },
									{ label: 'Plain Text', value: 'plaintext' },
								],
							},
						],
					},
				],
			}),
			FixedToolbarFeature(),
			InlineToolbarFeature(),
		],
		...config,
	});

Problem that we are facing is that whenever we click on "Publish in English" it throws an error "Relationship value should be a string or number. The Lexical Relationship component should not receive the populated value object."

obraz obraz

This error does not happen when:

  • we save collection as draft
  • we publish it to all locales

Another thing is that even the fact that error is displayed, we are still having an value as object in API (which is something that we want). Question is - how can we prevent displaying this error, we are expecting the value to be an object and not to perform a lot of API calls based on value being an ID.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /