Home › Forums › Add-ons › Repeater Field › prevent remove or edit fields after update post › Reply To: prevent remove or edit fields after update post
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();
});
});
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.