Support

Account

Home Forums Bug Reports Cloned fields inherit/save data to and from sibling cloned fields (with prefix)

Solved

Cloned fields inherit/save data to and from sibling cloned fields (with prefix)

  • There’s currently a bug with 2 cloned fields on the same page with “Prefix Field Names” selected and configured correctly (i.e. unique).

    The bug means that once one cloned field has been filled in, the second cloned field inherits that value. Meaning it’s impossible to have 2 cloned fields with unique IDs set via “Prefix Field Names”.

    I feel the reason for this is that although a datastore gets created with the prefixed field name correctly, the data collection on the front end has issues due to duplicate DOM input IDs on the form. Because of duplicate IDs I imagine this is causing issues when POST occurs on the Update button being clicked. (For more info see end of video)

    I have created a video showing this from start to finish which can be viewed here: https://drive.google.com/file/d/0B1K2tcYO_XFjYWNpZWMtWk5qV1k/view?usp=sharing (Download the video to stop Google Drive downscaling)

    I have also included my ACF JSON export: https://drive.google.com/file/d/0B1K2tcYO_XFjSHN6OFlJVGd0T1k/view?usp=sharing

    To repeat manually:
    – Create a field group named text fields
    – Add a number text fields in all with unique IDs
    – Save
    – Create a field group with the Flexible Content field type
    – Add a clone field type, select the field created in step 1, ensure field has a unique label, select “Prefixed Field Names”
    – Add another clone field type, select the field created in step 1, ensure the field has a unique label, select “Prefixed Field Names”
    – Show the field group on Page
    – Go to the page, populate one clone field’s contents but not the other
    – Click update
    – Both cloned field values will share that of the first cloned field

    If you view the fields in inspector you will see that both fields share the same DOM input ID.

    This bug is present on ACF 5.4.4

  • This reply has been marked as private.
  • Thanks James,

    I reported this through a support ticket also and Elliot replied and updated the clone field documentation to reflect this behaviour / support

    For anyone wondering about this it’s not currently something which can be implemented due to the way key names are setup. It’s my understanding that if the change was to be made to support this it would be a “breaking” change in ACF for users who currently have cloned fields on their setups

    Cheers

  • I know this is marked as solved, but there is a way to get this to work (tested on ACF Pro 5.4.1).

    Follow the same steps as outlined by fatsoma in “To repeat manually:” only change the Display from Seamless to Group within each clone field.

    This allows each duplication of the same clone content to be saved into the posts meta. This “feature” may be (probably is) a bug as from here you can’t access the data using the normal have_rows() and get_sub_field() method, but instead need to build your own.

    I’m using something like:

    
      // get the flexible content
      $flexible_content = get_field('flexible_content_name');
    
      foreach( $flexible_content as $flexible_row ) {
    
        // find out which layout is being used
        $acf_fc_layout = $flexible_row['acf_fc_layout'];
        echo '<h1>'. $acf_fc_layout .'</h1>';
    
        // knock the first index off to get at the goodies
        array_splice($flexible_row, 0, 1);
        
        // get content data
        foreach($flexible_row as $key=>$val) {
          echo '<h1>'.$key.'</h1>';
          ?><pre><?php
          print_r($val);
          ?></pre><?php
          echo $val['field_name'];
        }
      }
    

    to get at the fields which is pretty janky, but works.

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

The topic ‘Cloned fields inherit/save data to and from sibling cloned fields (with prefix)’ is closed to new replies.