Support

Account

Home Forums Add-ons Repeater Field Hook to force repeater rows collapse on load

Solving

Hook to force repeater rows collapse on load

  • I have a page I’m creating with ACF that is using a repeater google map for map markers. Unfortunately the markers are getting a bit out of hand and it’s causing some browser lag due to 200+ Google maps trying to render in at once. Currently I went in to repeater.php and forced the -collapsed class to always return true, however is there a hook or action I can use to make them always collapsed on load?

  • Hi @jostrander

    I believe you can use the acf/input/admin_footer hook to add the collapse class to the field. It should be something like this:

    function my_acf_admin_footer() {
    	?>
    	<script type="text/javascript">
        (function($) {
            
            $(document).ready(function(){
                
                $('.acf-field-1234567890 .acf-row').addClass( "-collapsed" );
                $('.acf-field-1234567890 .acf-field-abcdefghijklm').addClass( "-collapsed-target" );
                $('.acf-field-1234567890 .acf-field-abcdefghijklm').attr( "colspan", "2" );
                
            });
            
        })(jQuery);    
        </script>
    	<?php
    }
    add_action('acf/input/admin_footer', 'my_acf_admin_footer');

    Where “1234567890” is the field key of your repeater field and “abcdefghijklm” is the field key of the subfield you want to show.

    I hope this helps. Thanks!

  • Hi James,

    the solution works great for me. Do you have any idea that nested repeater get expand by clicking on the parent repeater? That would be great.

    Thank you in advance
    Sebastian

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

You must be logged in to reply to this topic.