Home Forums ACF PRO Disable Remove "Saved" Repeater Rows Reply To: Disable Remove "Saved" Repeater Rows

  • I have done this is the past, but I did it using only JS.
    This is the code I used. Basically, I have a list of fields that I want the client to be able to add values to and I want the to be able to reorder those values, but I do not want them to be able to delete a value. My reason is that these are used for values in a search and removing an existing value could cause a “product” to not appear anywhere on the site because it has a value that cannot be searched for, the search fields and the ACF fields on the “product” post page are both populated with these values as choices. I’ve added a few notes about what’s going on

    // readonly existing values and remove the remove row link
    // on several repeaters on product options page
    // list of the repeaters I want to disable and prevent deletion
    var repeaters = [
    // build the selector to get all of the repeater rows
    var selectors = [];
    for (i=0; i<repeaters.length; i++) {
      selectors[selectors.length] = '[data-key="'+repeaters[i]+'"] .acf-row';
    var selector = selectors.join(', ');
    // loop over all rows of all repeaters
    $(selector).each(function(index, element) {
      if ($(element).hasClass('acf-clone')) {
        // clone field, we don't do the clone field
        // this allows a new row that is added to be deleted before save
      // find the input field and set it to readonly
      $(element).find('.acf-input input').attr('readonly', true);
      // in my case I have another field that is populated with the number of "products"
      // associated with this value. If this is 0 then the client can delete it
      if ($(element).find('[data-name="product_count"] .acf-input input').val() == '0') {
      // remove the ACF remove row element so it cannot be triggered