Support

Account

Home Forums Backend Issues (wp-admin) acf/fields/flexible_content/layout_title

Solved

acf/fields/flexible_content/layout_title

  • Issue regarding the filter for the layout title of a flexible field.

    The Custom layout title disappears when I toggle the flexible field.
    The Default value does not show when I add a new flexible field.

    
    function keep_calm( $title, $field, $layout, $i ) {
    	$title = '';
    	if($text = get_sub_field('monkey')) {
    		$title .= '<span>' . $text . '</span>';
    	}
    	return $title;
    }
    
    add_filter('acf/fields/flexible_content/layout_title/name=cool', 'keep_calm', 10, 4);
    
  • 1) is “cool” the name of the flex field?

    2) is “monkey” the name of a field in the flex field? The sub fields of a flex field will not have a value until the post is saved.

    3) This will always return true because $text will always be set to something.

    
    if($text = get_sub_field('monkey')) {
    

    try

    
    $text = get_sub_field('monkey');
    if ($text) {
    
  • 1: Yes
    2: Yes
    3: Okey

    It must be js issue because when I update or visit my post, the value is there, but as soon as I toggle the flex field, the text(value of the subfield) disappears from the flex field and are updated with nothing ($title = ”;)

    Thanks.

  • I’m not seeing any errors or problems on my test site.

  • I just noticed that at the begining, you are setting $title to an empty string. if the if statement does not run then you’ll always be returning an empty string. try removing the first line of your function.

  • When I toggle a flex field the html of the div “.acf-fc-layout-handle” are “reloaded”, thats why the values disappears on click toggle..

  • I just tried this, and it does not work either, because the “.acf-fc-layout-handle” “cleans” the div again.. I can see the value being added to the “.acf-fc-layout-handle” for a short second and then it´s gone.. 😉

    
    function showstopper(obj) {
            obj.each(function() {
                var obj = $(this);
                var target = obj.closest('.layout').children('.acf-fc-layout-handle');
                var value = ' <span>' + obj.find('input').val() + '</span>';
                target.append(value);
            });
        }
    
        acf.add_action('ready', function() {
            showstopper($('.dog'));
        });
    
        acf.add_action('hide_field', function($field, context) {
            showstopper($field);
        });
    
        acf.add_action('show_field', function($field, context) {
            showstopper($field);
        });
    
  • Found an Issue in function “render_layout_title” in file “acf-pro-input.js”.
    The html returned upon “success” does not include the sub_field.
    If I comment/remove the function:

    
    $layout.find('> .acf-fc-layout-handle').html( html );
    

    Then it´s working… 😉

  • Please submit a new support ticket about this if you think it’s a bug so that the developer can look at it https://support.advancedcustomfields.com/new-ticket/

  • hi there,

    i am trying to get this to function to work, i have called the Field ‘blocktitle’

    i have added the following function to the function.php, what do i have to do next to make it work? the documentation is not clear

    function my_acf_flexible_content_layout_title( $title, $field, $layout, $i ) {

    // remove layout title from text
    $title = ”;

    // load sub field image
    // note you may need to add extra CSS to the page t style these elements
    $title .= ‘<div class=”thumbnail”>’;

    if( $image = get_sub_field(‘image’) ) {

    $title .= ‘‘;

    }

    $title .= ‘</div>’;

    // load text sub field
    if( $text = get_sub_field(‘text’) ) {

    $title .= ‘<h4>’ . $text . ‘</h4>’;

    }

    // return
    return $title;

    }

    // name
    add_filter(‘acf/fields/flexible_content/layout_title/name=my_flex_field’, ‘my_acf_flexible_content_layout_title’, 10, 4);

  • The Issue is now fixed in version 5.4.8
    “Flexible Content field: Fixed bug in ‘layout_title’ filter preventing values being loaded correctly…”

    🙂

  • This started messing up for me. I’m not sure if I added a field that made it start to glitch but it looks like when it loads the page get_sub_field('section_title') will get the appropriate value for each row but when I expand/collapse the row it will return NULL. Would this be a JS issue?

  • This is happening to me as well. Fields load and look normal but as soon as I expand a flexible-content layout they disappear. Only seems to be certain ones as the way I’m changing the title of the flex-content layout remains on expand and collapse.

Viewing 13 posts - 1 through 13 (of 13 total)

The topic ‘acf/fields/flexible_content/layout_title’ is closed to new replies.