Home Forums Add-ons Repeater Field Disable Repeater 'Add Row' Button


Disable Repeater 'Add Row' Button

  • I’d like to modify my Repeater buttons/links based on the current User’s role, disabling them (or adding a class) so that only certain users with the proper capabilities can add more rows. After some searching here, I have what seems to be an almost-working solution, but I don’t think the buttons exist yet when my function runs (code shown below).

    Is there a flag that I can listen for to know when all of the ACF fields and elements are finished loading? Thank you.

    add_filter('acf/load_field', 'check_ACF_permissions');
    function check_ACF_permissions($field) {
    	global $post;
    	if ($post->post_name == 'project-tracker') {
    		$field['readonly'] = 1;
    		?><script type='text/javascript'>jQuery('.acf-actions').data('event', '');</script><?php
    		$userRoles = ( km_get_user_role() );
    		foreach($userRoles as $r => $role) {
    			if ($userRoles[$r] == 'project-manager') {
    				$field['readonly'] = 0;
    				?><script type="text/javascript">jQuery('.acf-button').data('event', 'add-row');</script><?php
    	return $field;
  • For reference, this thread was very similar but unfortunately no solution was presented:

    Disable Update button until all fields have loaded

  • Well, I thought this would work:


    …but it fires before the acf/load_field filter runs.

  • You would need to add you own custom JavaScript You could localize this with information about the current user and based on that you could remove the buttons. Unfortunately, without spending the time to actually build something that will do this I can’t really help you more than than.

  • Thanks for your reply; I got it working like this (using acf/load_field to first check permissions and set a global var):

    add_action ( 'admin_footer', 'check_ACF_permissions_button' );
    function check_ACF_permissions_button($post) {
    	if ($GLOBALS['projectManager'] === false) {
    		?><script type="text/javascript">
  • Hello,

    I resolved this problem with:

    add_filter('acf/load_field/type=repeater', 'disable_repeater');
    function disable_repeater($field) {
    		if($field['readonly'] || $field['disabled']){
        <script type='text/javascript'> 
            acf.addAction('load', function(){
              jQuery('.acf-actions, .acf-row-handle').remove();
    	return $field;
  • @vanian , @p-j-albuquerque Thanks for sharing!
    I used acf/load_field/type=repeater for new post & form generation (ie. not for edit)
    Realizing that ALL repeaters are affected.

  • {
    foreach (RepeaterItem rptItem in Repeater1.Items)
    if (rptItem.FindControl(“lbtnTest”) != null)
    ((LinkButton)rptItem.FindControl(“lbtnTest”)).Enabled = false;

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

The topic ‘Disable Repeater 'Add Row' Button’ is closed to new replies.