Support

Account

Home Forums Add-ons Repeater Field prevent remove or edit fields after update post

Helping

prevent remove or edit fields after update post

  • Dear Friends,
    I have a repeater field ” Message Content “, i need that a user role can add row and fill it, but after updating post he couldn’t remove or edit filled row. it will use as a reporting system.

    How can i do it ?

    Thanks

  • This has to be done with JavaScript, what you need to do is physically remove the delete row buttons. See this document on adding custom JS https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/

    The following code is copied directly, it removes the delete row button from several repeaters. It leaves the delete row button if another field in the row is set to “0”. You’ll probably want to remove that check. This does allow the rows to be reordered. You might want to figure out how to remove the element that allows dragging the rows and quite possibly adding a row between other rows. But this is a starting point

    
    jQuery(document).ready(function($) {
      if (typeof(acf) == 'undefined') {
        return;
      }
      
      // readonly existing values and remove the remove row link
      var repeaters = [
        'field_59dd19d721413',
        'field_59de2a200f0a3',
        'field_59de3024dff85',
        'field_59de3fc95cf01',
        'field_59de4773cb4ee',
        'field_59de4e4784bac',
        'field_59e0dec7330d9',
        'field_59e0d5657109a',
        'field_59e0e934032c3',
        'field_59e4d54db8896',
        'field_59e4d7f348352',
        'field_59e4ea9adfa00',
        'field_59e60f342dae3',
        'field_59e61cce68a09'
      ];
      var selectors = [];
      for (i=0; i<repeaters.length; i++) {
        selectors[selectors.length] = '[data-key="'+repeaters[i]+'"] .acf-row';
      }
      var selector = selectors.join(', ');
      //console.log(selector);
      $(selector).each(function(index, element) {
        if ($(element).hasClass('acf-clone')) {
          return;
        }
        $(element).find('.acf-input input').attr('readonly', true);
        if ($(element).find('[data-name="product_count"] .acf-input input').val() == '0') {
          return;
        }
        $(element).find('a[data-event="remove-row"]').remove();
      });
      
    });
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘prevent remove or edit fields after update post’ is closed to new replies.