Ok i have updated the code and now it works but somehow you need to have atleast one layout in flexible content for dragging to work.
add_action('acf/input/admin_footer', function () {
?>
<script type="text/javascript">
(function($) {
acf.add_action('ready', function($el){
$(".acf-flexible-content .values").sortable({
connectWith: ".acf-flexible-content .values",
start: function(event, ui) {
acf.do_action('sortstart', ui.item, ui.placeholder);
},
stop: function(event, ui) {
acf.do_action('sortstop', ui.item, ui.placeholder);
$(this).find('.mce-tinymce').each(function() {
tinyMCE.execCommand('mceRemoveControl', true, $(this).attr('id'));
tinyMCE.execCommand('mceAddControl', true, $(this).attr('id'));
});
}
});
$(".acf-repeater .acf-flexible-content").sortable({
connectWith: ".acf-repeater .acf-flexible-content",
start: function(event, ui) {
acf.do_action('sortstart', ui.item, ui.placeholder);
},
stop: function(event, ui) {
acf.do_action('sortstop', ui.item, ui.placeholder);
}
});
});
acf.add_action('sortstop', function ($el) {
var $repeater = $($el).closest('.acf-input > .acf-repeater');
if ($repeater.length) {
var $row = $el.closest('.acf-row');
var column_num = $row.attr('data-id');
// Loop through fields within the dropped element and update names
$el.find('[name^="acf[field_"]').each(function() {
var field_name = $(this).attr('name');
field_name = field_name.match(/\[([a-zA-Z0-9_-]+)\]/g);
field_name[1] = '[' + column_num + ']';
var new_name = 'acf' + field_name.join('');
$(this).attr('name', new_name);
});
// Loop through layouts within the flexible content field
$repeater.find('.acf-flexible-content .values > .layout').each(function(index) {
$(this).find('.acf-fc-layout-order:first').html(index + 1);
// Loop through fields within each layout and update names
$(this).find('[name^="acf[field_"]').each(function() {
var field_name = $(this).attr('name');
field_name = field_name.match(/\[([a-zA-Z0-9_-]+)\]/g);
var tempIndex = parseInt(field_name[3].match(/([0-9]+)/g));
field_name[3] = field_name[3].replace(tempIndex, index);
var new_name = 'acf' + field_name.join('');
$(this).attr('name', new_name);
});
// Trigger click on selected buttons to activate conditional logic
$(this).find('.acf-button-group label.selected').trigger('click');
});
}
});
})(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;
}
</script>
<?php
});
That is not a solution really, its been 2 years and no response?
John what if we only want to include custom fields and no fields from acf_form, how can we do that?
I have tried the fix but i guess it doesn’t seem to work with Option Page.
Figured it out 😉
<?php if( have_rows('optionpage', 'option') ): ?>
<?php while( have_rows('optionpage', 'option') ): the_row(); ?>
<?php
$layout_type = get_sub_field('page_layout');
if ($layout_type == 'vertical'){
echo 'vertical';}
else {
echo 'horizontal';}
?>
<?php endwhile; ?>
<?php endif; ?>
Hi @acf-support You Rock My Friend, It totally worked 🙂
Hi,
I am trying this, can you explain how do i replace ?thankid= with my page link.
My redirection page link is http://localhost:8888/wordpress/thank-you
I have tried both, maybe i can give you actual field names so you can tell me what do i include in my page template for thank you page.
Field Name : sb-pickup-location
Once you select the location and submit the form i want the selected value of sb-pickup-location to be displayed on thank you page.
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.