Support

Account

Home Forums Backend Issues (wp-admin) How to get/set repeaters field cloneindex?

Solved

How to get/set repeaters field cloneindex?

  • I might be the going the wrong direction here, but I am having an weird issue..

    I created a custom field which mostly mimics the checkbox field.

    When inside the repeater field the acf checkbox field $field[‘name’] automatically replaces [cloneindex] with a random ID, or with the actual index (if the field has already been saved).

    For my custom field the [cloneindex] is not replaced. Instead the actual words [cloneindex] shows up. This prevents me from saving multiple rows of a repeater field.

    is there any thing in the render_field function that needs to be there in order for the cloneindex to be update? Or do I need to do it via js manually?

  • is it [cloneindex] or [acfcloneindex] I’ve done a search of ACF and it does not actually use cloneindex anywhere, only acfcloneindex.

  • Sorry… it’s acfcloneindex.

  • That makes it more difficult, the best I can tell you is to look at the html and all the classes and id values in it to make sure that everything that’s needed is there. The only thing that I can think of is that you’re missing a class or something that ACF is looking for. I’ve also looked through the ACf code trying to figure out what it is looking for and why it wouldn’t be replacing it in your field and I can’t figure it out. Some of the JS is just over my head.

  • No problem. Thanks for taking a look. I have also been digging through the js files. Trying to figure out how the value is passed.

  • So, I think it happens on line 1811 (starts at duplicate: function( $el, attr ){) of /assets/js/acf-input.js. It looks for the ‘data-id’ attribute, which in this case should be acfcloneindex and replaces it with a unique id. The field name replacement is this part

    
    // replace names
    				$el2.find('[name*="' + find + '"]').each(function(){	
    				
    					$(this).attr('name', $(this).attr('name').replace(find, replace) );
    					
    				});
    

    is acfcloneindex being replaced anywhere in your field? all occurrences for that string should be replaced in id attributes, labels, names, etc.

  • Thanks. I think that will help me solve my issue. My custom field creates more field inputs via js, but the ids are not replaced because I am passing them using my own data attribute and the code is looking for the attribute ID.

  • Problem fixed. I created a dummy field to capture the acfcloneindex and from their I can pass it to my js file.

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

The topic ‘How to get/set repeaters field cloneindex?’ is closed to new replies.