Support

Account

Home Forums Gutenberg Javascript API for fields in block Edit mode

Helping

Javascript API for fields in block Edit mode

  • Hello,

    For many of our client we need to include custom fields validation through the ACF javascript API, which is great.

    We are now creating block with ACF and we are wondering if there are filters/actions in the API for fields in the edit mode of blocks.

    For example, we need to replicate the feature in which a field is autocompleted based on a field above it (exactly what happens when you create a field in the ACF gui, the Field name is auto populated according to the Field label field above).

    In normal ACF metabox, I would do with something like that

    
    acf.add_action( 'load_field/name=label', function() {
    
      // Bind change event
    
      // autopopulate the below field, previously targetted
    });
    

    But now as the fields are loaded through AJAX the above code would not work because it’s not ran when the block is selected and in edit mode.

    Is there any action/filter in the JS API that is related to the Blocks, when it is selected or change from preview/edit mode ?

    Thanks

  • I managed to implement this with:
    acf.addAction('new_field/name=my_field', myCallback);
    Hope it helps anyone!

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Javascript API for fields in block Edit mode’ is closed to new replies.