Home › Forums › Feature Requests › Drag Flexible Content layouts between parent Repeaters › Reply To: Drag Flexible Content layouts between parent Repeaters
Success! I had wrote a script that modifies the name attribute of elements to match the new column and element locations. It’s hooked into the sortstop action. This code should work on most any setup with only two substitutions, the [data-name=”elements”] and [data-layout=”columns”] attributes are specific to my setup. It uses a nested flexible content field structure where the columns are a layout under the primary flexible content field. Elements is another flexible content field that’s part of the column layout.
// Handle Dragging Between Columns
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);
});
});
}
});
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 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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.