Support

Account

Home Forums Gutenberg Hide fields depending on block styles

Solved

Hide fields depending on block styles

  • Hi,

    I would like to know if it’s already possible to hide some fields depending on the block style. Has anyone ever done it by overriding some settings in the WordPress JS API? otherwise, it would be super cool to add that as a conditional check per field or simply each block style having a different ACF location… 🤔

  • I’m also interested to know how this might be done. Same goes for the new block variations, which is really cool.

    ref: https://make.wordpress.org/core/2020/02/27/introduce-block-variations-api/

  • I just found my question by searching again for this as I need it again for another project and I didn’t remember I had already asked. 💀

    I really would like this. I’ve noticed there’s talk about an ACF_Location overhaul in 5.9, but we have yet to learn what it entails.

  • +1. Would love this functionality too. Then I can move away from dropdown fields to handle block styles

  • Alright, I got an OCD moment because I come back to this post every 6 months checking in if it’s been done so I wanted to give it a go.

    I’m 99% there with only filters: https://gist.github.com/davidwebca/efe3bb9f69df0a0f007179c59872054a

    With that, it works on full reload of the page in the admin, but not with changes, style changes or AJAX re-rendering… And you have to visit a Gutenberg page to activate the block styles cache, otherwise there’s no way WordPress knows about the block styles registered (🙄).

    Other than that small limitation, only thing that I miss is the ability to force the re-rendering of the ACF form components. As far as I know, my AJAX works and the filtering out of the field group works, but the forms don’t re-render or reload according to changes in the form. Might have to add filters in acf-pro-blocks.js? Maybe we can already do that with JS filters / force JavaScript events?


    @hube2
    Thoughts?

  • Just for reference, I found this post in the forum from John about extending acf.ajax to be able to trigger the re-rendering of the form. I’ll look into that, even though his example is a broken link, I’m pretty sure I know what to do. https://support.advancedcustomfields.com/forums/topic/custom-location-rule-js-refresh/

  • Aaaand I figured it out. Warning: this is very much hacked around. We should never access React instances from the outside and call their methods without having been passed the instance from an event or something. But until we get the proper hooks and APIs from ACF and WP core, this is pretty much as close as it gets. https://github.com/davidwebca/acf-block-style-location

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

The topic ‘Hide fields depending on block styles’ is closed to new replies.