-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: onChange for InnerBlocks? #11271
Comments
I just mentioned this in #6751 too. And also saving I don't know if either of these are technically feasible though. |
@earnjam I think this should be changed to feature request for |
@raquelmsmith did you ever figure out a solution for this? I would like to use InnerBlocks.Content from the parent block to generate some schema. |
If you want to retrieve the list of blocks and use it elsewhere, see my reply here #10745 (comment) If you want to check whether any of the inner blocks change over time to do something, I think your best bet here is to use the data module and the withSelect(
( select, { clientId } ) => {
return {
innerBlocks: select( 'core/block-editor' ).getBlocks( clientId )
};
}
)( MyBlockEditFunction ) |
@youknowriad thanks for this, just noticed a minor issue that the select should be 'editor' rather than 'block-editor' but I can confirm this works. @raquelmsmith this should get you close to what you need, if you use this edit for you parent block you should see a log of the innerBlocks.
|
@scottblackburn 'block-editor' is the new package extracted from the existing 'editor' package. It will be available in the WordPress 5.2 Core Gutenberg version: https://make.wordpress.org/core/2019/04/09/the-block-editor-javascript-module-in-5-2/ |
Hi there, just looking for an update or possible solution for this. I took a look at the 'block-editor' mentioned by @scottblackburn, but didn't have any luck. I know the code provided is incorrect, but here is what I'm trying to achieve:
I was able to successfully create and save Post Meta using a custom block following this tutorial: https://developer.wordpress.org/block-editor/tutorials/metabox/meta-block-1-intro/ However, I have not been able to save the InnerBlocks content to the meta field. You'll notice I've include 2 different methods for trying to save the content to the meta field. The InnerBlocks has been used with a restricted template to ['core/table'], as I couldn't figure out how to add just a Table block. Obviously, I am also quite new at developing with Blocks :D ( function( blocks, editor, i18n, element, components, _ ) {
var el = wp.element.createElement;
const { InnerBlocks } = wp.blockEditor;
var ALLOWED_BLOCKS = [ 'core/table' ];
var TEMPLATE = [
[ 'core/table' ]
];
blocks.registerBlockType( 'rogue-theme-custom-blocks/rogue-product-specifications-block', {
title: i18n.__( 'Product Specifications', 'rogue-theme-gutenberg-blocks' ),
icon: 'index-card',
category: 'layout',
attributes: {
blockValue: {
type: 'string',
source: 'meta',
meta: 'sm_product_specifications_meta_block_field'
}
},
edit: function( props ) {
var attributes = props.attributes;
var setAttributes = props.setAttributes;
function updateBlockValue( blockValue ) {
setAttributes({ blockValue: InnerBlocks.Content});
}
return (
el( 'div', { className: 'product-specifications ' + props.className },
el( InnerBlocks, {
value: attributes.blockValue,
onUpdate: updateBlockValue,
allowedBlocks: ALLOWED_BLOCKS,
template: TEMPLATE,
templateLock: true
} ),
)
)
},
save: function( props ) {
props.setAttributes({blockValue: InnerBlocks.Content});
return null;
},
} );
} )(
window.wp.blocks,
window.wp.editor,
window.wp.i18n,
window.wp.element,
window.wp.components,
window._,
); Thank you! |
I have a nested (parent) block with a number of items inside. When the content changes inside those innerblocks, I want to run a function. I don't see an onChange prop for InnerBlocks, and when I tried it didn't work. Any ideas how to go about this?
The text was updated successfully, but these errors were encountered: