Support

Account

Home Forums Backend Issues (wp-admin) ACF javascript always making fields visible?

Solved

ACF javascript always making fields visible?

  • I’m converting a site from using regular custom meta boxes over to ACF Pro. The site had conditional logic based on the Post Format selected to display/hide certain meta boxes. After converting to ACF Pro and updating the previous javascript file with the new IDs, there is something in the ACF javascript file acf-input.js that causes the meta box to always display. I’m logging each step in my script file and can see that mine is trying to hide the meta box, and as soon as i hide it, it comes right back. If I get rid of of acf-input.js (temp rename it on the server) my script is working as expected (showing/hiding meta boxes depending on the post format). Also, my script is working correctly on all non-ACF Pro fields/meta boxes (postdivrich, postimagediv, categorydiv, etc).

    I’m not seeing anything in the ACF documentation on how I need to implement my external conditional logic, or how I can tell ACF to let me control the visibility of these particular fields. I’m sure I’m missing something obvious and am hoping someone can point me in the right direction.

  • ACf has it’s own location rules, for example, post format. You can set the rules for where each field group appears in the location. ACF also has conditional logic that can determine when an individual field appears. These rules can be based on choice fields (select, checkbox, radio) in the same field group. In order to extend this logic you would need to extend the JavaScript in ACF. I don’t think there is any way to include your own external conditional logic, at least not something that could be considered easy and there isn’t much in the way of documentation for extending the JS in ACF. If what you want is not built into ACF then you’ll probably need to re-code all the custom stuff and not just change the IDs of the fields in the existing JS.

  • i knew i was just overlooking something. I had not noticed that there was an option for “Post Format” in the location rules. That’s exactly what i needed. Thanks, @hube2 !!

  • for the ACF fields attached to post format i was able to use the location rules. for the non-acf fields I was able to update my javascript so there were no longer conflicts between it and ACF’s js. The key piece was the post format in the location rules. just completely overlooked that.

  • ACf also gives you the ability to add custom location rules https://www.advancedcustomfields.com/resources/custom-location-rules/ I have created several examples based on questions people have asked here https://github.com/Hube2/acf-filters-and-functions

  • VERY handy to know about. Thanks for pointing that out. I do have a couple of situations where things need to alter slightly for users with contributor permissions. Will definitely come in handy

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

The topic ‘ACF javascript always making fields visible?’ is closed to new replies.