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');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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.