Home › Forums › Gutenberg › Block Data changes after field change › Reply To: Block Data changes after field change
Well, I think I found a solution to this in the most Gutenberg way possible.
Set block template javascript variable in the template, then read that variable instead of relying on wp.data.select(“core/block-editor”).
Since Gutenberg is all about saving the data into the html this seemed like the best way to get field data from other blocks.
<?php
// Dynamic block ID.
$block_id = 'repeater-' . $block['id'];
$blockClasses = implode( ' ', array( $block['className'] ) );
$per_page = get_field( 'per_page' );
$allowed_blocks = array( 'acf/card' );
?>
<div id="<?php echo $block_id; ?>" class="<?php echo $blockClasses; ?>">
<InnerBlocks templateLock="false" allowedBlocks="<?php echo esc_attr( wp_json_encode( $allowed_blocks ) ); ?>"/>
</div>
<div class="items-repeat"></div>
<script>
var <?php echo $block['id']; ?> = {
'per_page': <?php echo $per_page; ?>
}
</script>
Then in my javascript onchange I can get the block / field from the variable
window[block.attributes.id].per_page
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.