Support

Account

Home Forums ACF PRO ACF Slider not firing in preview mode

Solving

ACF Slider not firing in preview mode

  • Hey peeps

    Hope you are all well

    I’ve built a custom block for a carousel, I have the block all working and the carousel working on the frontend.

    Only issue is, in preview mode in the editor, the init.js isn’t firing for the carousel.

    All the scripts are there, just not working in the admin, so the preview won’t show the carousel.

    My init.js file below.

    
    (function($){
    
        var initializeBlock = function( $block ) {
            $(".owl-carousel").owlCarousel({
                  margin: 10,
                  nav: true,
                  navText: '',
                  loop: true,
                  autoHeight:false,
                  responsive: {
                    0: {
                      items: 1
                    },
                    768: {
                      items: 2
                    },
                    1024: {
                      items: 3
                    }
                  }
            });
        }
    
        // Initialize each block on page load (front end).
        $(document).ready(function(){
          initializeBlock();
        });
    
        // Initialize dynamic block preview (editor).
        if( window.acf ) {
            window.acf.addAction( 'render_block_preview/type=owl-carousel', initializeBlock );
        }
    
    })(jQuery);
    
    
  • I suggest you to use “Slick Slider” it is way more flexible, faster, better, everything. I know it does not help but when I see someone using this retarded OWL slider I want to prevent them to make a big mistake 😉

    • webprom

    • January 28, 2020 at 3:21 am

    Maybe you need to use $block.find(".owl-carousel").owlCarousel({

    https://www.advancedcustomfields.com/blog/building-a-custom-slider-block-in-30-minutes-with-acf/

    • jkgk

    • June 5, 2020 at 2:25 am

    The issue here is initializeBlock is not being fired as the condition type=owl-carousel is not being met for render_block_preview.

    I had the same issue.

    I currently have support ticket waiting, as type seems to the name of the the block registered by <?php acf_register_block_type(), but maybe there is something more to it.

    In the mean time, I have removed the type parameter. Slight issue is that the initializeBlock runs on every ACF block loaded, but that is not a huge issue for me at this point.

    Hope that is of some help, Joe.

    • Elliot

    • June 12, 2020 at 8:56 am

    Hi @jm_design

    Thanks for the topic.

    Can you please post the PHP used to register your block type?
    I’ll use this to setup a local version of your block and get to work on diagnosing the issue 🙂

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.