Hello,
I’m trying to close all flexible fields by default, so that when the edit page initially loads only the title of each flexible content layout is visible.
I’m currently using this script:
function my_acf_admin_head() {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.layout').addClass('-collapsed');
});
</script>
<?php
}
add_action('acf/input/admin_head', 'my_acf_admin_head');
This does close all fields but it also closes fields that are then added to the page via the ‘Add Content’ button. Not sure why this is as I thought the above script would only run on initial page load?
Any help greatly appreciated.
Thanks,
Shaun
ACF includes a copy of layout that is uses to create a new layout by copying these. When you are setting the layouts to collapse you are also setting these copies.
your selector should look something like this… I think, you may need to inspect the html to find them and target them, but this is the general idea
$('.layout').not('.clones .layout').addClass('-collapsed');
Ah, that would explain it.
Thanks for your help @hube2, appreciate it.