Support

Account

Home Forums Add-ons Repeater Field Minimum Rows 1 empty fields shows as value

Solved

Minimum Rows 1 empty fields shows as value

  • Hi, Id like to show blank row for each repeater – So I set min rows to 1. However this creates empty fields that seem to have a value.

    if( get_field('product_watt_replacement') ) {
    
        $content .=  '<tr><td>' . 'Wattage Replacement</td><td>'; 
        while ( have_rows('product_watt_replacement') ) : the_row();
        	 $array2[] = get_sub_field('watt_replacement')  .'w'; 
        endwhile;
        	$watt = implode(', ', $array2);
    
        $content .=  $watt .'</td></tr>'; 
    } 

    With min rows 1 the empty fields still show the html tags even though the fields are blank. Please advise.

  • That’s because with 1 row, when you save the post ACF created the row and adds the blank content. So have_rows() is true and it loops through the rows to show them, even though they are blank.

    You’ll need to loop though the fields to see if there’s actually anything in them before showing them

    
    
    if( get_field('product_watt_replacement') ) {
        while ( have_rows('product_watt_replacement') ) : the_row();
             $value = get_sub_field('watt_replacement');
             if ($value) {
        	     $array2[] = get_sub_field('watt_replacement')  .'w'; 
             }
        endwhile;
        if (count($array2[])) {
            $content .=  '<tr><td>' . 'Wattage Replacement</td><td>'; 
        	$watt = implode(', ', $array2);
            $content .=  $watt .'</td></tr>';
        }
    }
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Minimum Rows 1 empty fields shows as value’ is closed to new replies.