I have a couple of RichText fields in my block, and a few other controls of misc types (none RichText) in my inspector. Simplified, this is how they're configured:
const CFG = {
rich : {
className : 'my-rich-classname',
keepPlaceholderOnFocus : true,
placeholder : 'Title',
selector : '.my-rich-classname',
source : 'html',
tagName : 'h2',
},
simple : {
className : 'my-simple-classname',
label : 'Choose...',
type : 'string',
options : []
}
};
registerBlockType( 'example/block', {
// usual stuff
attributes: {
...CFG
},
edit: function( props ) {
const onTextChange = ( key, val ) => {
props.setAttributes( { [ key ] : val } );
};
let rich = props.attributes.rich;
let simple = props.attributes.simple;
console.log( 'edit', props.attributes );
return(
wp.element.createElement(
'div',
{},
wp.element.createElement(
wp.editor.InspectorControls,
{},
wp.element.createElement(
wp.components.SelectControl,
{
label : CFG.simple.label,
className : CFG.simple.className,
options : CFG.simple.options,
value : simple,
onChange : val => {
onTextChange( 'simple', val )
}
}
)
),
wp.element.createElement(
wp.editor.RichText,
{
className : CFG.rich.className,
keepPlaceholderOnFocus : CFG.rich.keepPlaceholderOnFocus,
placeholder : CFG.rich.placeholder,
tagName : CFG.rich.tagName,
value : rich,
onChange : val => {
onTextChange( 'rich', val )
}
}
),
)
)
},
save: function( props ) {
console.log( 'save', props.attributes );
return null;
}
}
If I type "Howdy" into rich and make a selection in simple, my console reflects every keystroke properly, eventually ending up with:
edit > Object { rich: "Howdy", simple: "123abc" }
And when auto-saving or when clicking "save":
save > Object { rich: "Howdy", simple: "123abc" }
So the "rich" property is being updated and seemingly should be able to be saved...are certainly passed as attribute to the callback rendering function, eh?
But examining wp_posts, here's what's in post_content:
<!-- wp:example/block {"simple":"abc123"} /-->
In our callback, doing a var_dump( func_get_args() ):
0 =>
array (size=1)
'simple' => string 'abc123' (length=6)
1 =>
string '' (length=0)
It does not matter if I format RichText or not.
I have a couple of
RichTextfields in my block, and a few other controls of misc types (noneRichText) in my inspector. Simplified, this is how they're configured:If I type "Howdy" into
richand make a selection insimple, my console reflects every keystroke properly, eventually ending up with:And when auto-saving or when clicking "save":
So the "rich" property is being updated and seemingly should be able to be saved...are certainly passed as attribute to the callback rendering function, eh?
But examining
wp_posts, here's what's inpost_content:In our callback, doing a
var_dump( func_get_args() ):It does not matter if I format
RichTextor not.