RichText Component: Block validation error
-
Hey guys, in one of my custom blocks i use the RichText component.
I followed the guidelines here in these article: https://developer.ww.wp.xz.cn/block-editor/reference-guides/richtext/#example
Unfortunately, i receive in my console.log an Block validation error.
Content generated bysavefunction:
<h2 class="wp-block-studio-wai-heading studio-wai-heading has-object-object-font-size">Block 1 INNOVATIVE BRAND STRATEGY & SUCCESS</h2>
Content retrieved from post body:
<h2 class="wp-block-studio-wai-heading studio-wai-heading">Block 1 INNOVATIVE BRAND STRATEGY & SUCCESS</h2>The only difference i mentioned is the classname “has-object-object-font-size” which is added by save.js (see code above).
save.js:
const save = function ({ attributes }) {
const { content, heading } = attributes;
const blockProps = useBlockProps.save({
className: classnames('studio-wai-heading'),
});
return <RichText.Content {...blockProps} tagName={heading} value={content} />;
};edit.js:
return (
<RichText
{...blockProps}
tagName={heading}
value={attributes.content}
allowedFormats={['core/bold', 'core/italic']}
onChange={(content) => setAttributes({ content })}
placeholder={__('Heading...')}
/>
);attributes.js
content: {
type: 'string',
source: 'html',
selector: 'h1,h2,h3,h4,h5,h6',
},How i can solve the Block validation error?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘RichText Component: Block validation error’ is closed to new replies.