Search code examples
wordpresswordpress-gutenberg

Gutenberg: adding an "onChange" Event to specific block field


I have an existing Block which was created with LazyBlocks.

I need to overwrite the title and the post image of the current WordPress post when the corresponding field in the specific block is changed. I googled quite a bit but didn't got a clue.

Example:

Screen capture of block

Thanks for your help!


Solution

  • Lazyblocks provide different js-filters. Following is fired if a value of the specific block has changed.

    wp.hooks.addFilter( 'lzb.editor.control.updateValue', 'lazyblock/fmtest', function ( val, control, childIndex ) {
        console.log( val, control, childIndex );
        /*do your stuff*/
        return val;
    } );