Within my custom block plugin, I am using create-block to generate my block environment for block editing. Within my `src/edit.js file I have the following setup...
import { __ } from '@wordpress/i18n';
import {
useBlockProps,
Fragment,
RichText,
BlockControls,
} from '@wordpress/block-editor';
import './editor.scss';
export default function Edit( { attributes, setAttributes } ) {
const { text } = attributes;
// additional options for our RichText component - https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md
return (
<Fragment>
<BlockControls controls={[{
title: "Button 1",
icon: "admin-generic",
onClick : () => console.log("Button 1 clicked!"),
},]} />
<RichText
{ ...useBlockProps() }
onChange={ ( value ) => setAttributes( { text: value } ) }
value={ text }
placeholder={ __( 'My chocolate placeholder', 'chocolate' ) }
tagName="h4"
allowedFormats={ 'core/bold' }
/>
</Fragment>
);
}
...But when I run npm start, and go to my edit page, I get the following error in the console...
Block validation: Block validation failed for `course-blocks/chocolate` ( ....}
My save.js file looks like so...
import { useBlockProps, RichText } from '@wordpress/block-editor';
export default function save( { attributes } ) {
const { text } = attributes;
return (
<RichText.Content
{ ...useBlockProps.save() }
tagName="h4"
value={ text }
/>
);
}
and my attributes are being pulled from my block.json...
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "course-blocks/chocolate",
"version": "0.1.0",
"title": "Chocolate",
"category": "text",
"description": "A playground for block development.",
"supports": {
"html": false
},
"textdomain": "chocolate",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"attributes": {
"text": {
"type": "string",
"source": "html",
"selector": "h4"
}
}
}