Support

Account

Home Forums Feature Requests Drag Flexible Content layouts between parent Repeaters Reply To: Drag Flexible Content layouts between parent Repeaters

  • EDIT: It didn’t, see later post

    Thanks so much!

    It worked out if the box. The complete code is below (nothing new, just combined for easy copy&paste). This greatly enhances the use of ACF:

    Add to functions.php:

    
    // Handle Dragging Between Columns
    
    function my_acf_input_admin_footer() {
    
        ?>
    
            <script type="text/javascript">
            
            (function($) {
    
                $( ".values" ).sortable({
                  connectWith: ".values"
                })
    
            })(jQuery); 
    
            function GetSubstringIndex(str, substring, n) {
                var times = 0, index = null;
    
                while (times < n && index !== -1) {
                    index = str.indexOf(substring, index+1);
                    times++;
                }
    
                return index;
            }
            
            acf.add_action('sortstop', function ($el) {
                if ($($el).parent('[data-name="elements"] > .acf-input > .acf-flexible-content > .values').length) {
                    var column_num = $($el).closest('[data-layout="column"]').attr('data-id');
                    $($el).find('[name^="acf[field_"]').each(function(){
                        var field_name = $(this).attr('name');   
                        var index_location = field_name.indexOf(']')+2;
                        var new_name = field_name.substr(0, index_location) + column_num + field_name.substr(index_location+1)
                        $(this).attr('name', new_name);
                    });
                    $($el).closest('[data-name="elements"]').find('.acf-input > .acf-flexible-content > .values > .layout').each(function(index){
                        $(this).find('[name^="acf[field_"]').each(function(){
                            var field_name = $(this).attr('name');   
                            var index_location = GetSubstringIndex(field_name,']', 3)+2;
                            var new_name = field_name.substr(0, index_location) + index + field_name.substr(index_location+1);
                            $(this).attr('name', new_name);
                        });
                    });
                }
            });        
    
            </script>
    
        <?php
    
    }
    
    add_action('acf/input/admin_footer', 'my_acf_input_admin_footer');