Home Forums ACF PRO Loading jQuery when switching page template


Loading jQuery when switching page template

  • Hey guys!
    So i’m totally stuck here and i’m hoping some of you smart folks could maybe help out a poor sucker.

    So here’s the thing, I have created fields and all that good stuff for 2 templates, so different fields for 2 different templates. I have then made a lot of styling and positioning with the help of my good friend jQuery (obvs most of the styling is in the css but that’s not the problem)

    The problem here is that when you create a page and then select one of these templates you don’t get any of the jQuery stuff. If you publish/draft then there is’nt any problem but it should look correct from the beginning.

    I have tried so many things, like making ajax calls once page template is changed. If im not way of, when changing page template there is a ajax call that fetch all the fields that belongs to that template or something along those lines? So thats why the jQuery wont run.

    Im sure it’s a “easy” thing to do with jQuery but im stuck so im hoping to get some pro help 😉
    Im not down with the lingo so sorry about my so called “explanations”

    Im sure this isnt really specific to ACF /Pro but figured this was the best place to put it.

  • Can you somehow hook into this

    if( typeof acf !== 'undefined' ) {
    	acf.postbox.render({"id":"acf-group_551acc92f306d","key":"group_551acc92f306d","style":"seamless","edit_url":"http:\/\/themefolder\/wp-admin\/post.php?post=235&action=edit","edit_title":"Edit field group","visibility":false});	

    and give the newly visible fields the jquery i have created perhaps?

  • one solution, might be getto but that is to have all fields on all templates that will be using custom fields and just have them display:none.

    Then just do some checking with jquery on what page template were are on (#page_template) and also check if it changes and just add display:block on field blocks that should be displayed.

    Is this really bad? What would the performance be on the dashboard and the db if having let say 90 fields in total.

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

The topic ‘Loading jQuery when switching page template’ is closed to new replies.