Home Forums Add-ons Repeater Field Dynamically set limit for repeater rows


Dynamically set limit for repeater rows

  • Hi there…
    I am working on a list of activities for which users should sign up. For this I am using acf_form(), to display the form on the frontend.
    For each activity there is a desired number of persons.
    For the data of each person I am using a repeater to store name and email. So far, OK

    For instance:
    Activity A – requires 2 persons… So, if one person signs up, the next time someone is trying to sign up, there should be only one repeater row allowed to be created…

    I am currently doing the calculation “on the go” in the template to show/hide the acf_form based on this, but I would love to actually validate it the right way dynamically changing the maximum number of repeater rows allowed

  • Any luck finding an answer? Looking to do something similar right now.

  • Hey @malavigne
    Sorry to say, but I didn’t find a way to solve this, and I took a completely different approach using relationship fields to link both Custom Post Types (Persons and Activities, for instance).

    Still, I would love to see if someone has any thoughts about accomplishing my original question

  • There isn’t any way to do this using a single field because the repeater will contain all of the existing rows and trying to limit this number of rows will cause issues. There isn’t a way to have one repeater that can be use to add new rows without showing all of the rows.

    To do this you would need to have 2 different fields, one repeater that is used in the admin and one that is used only on the front end.

    You can put your second field into a different field group.

    You can then specify the fields that you want to show when calling acf_form().

    When the front end field is loaded then you can add an acf/load_field filter, check the number of rows in the “real” repeater and limit the front end repeater based on that number.

    Then you create an acf/save_post filter. In this filter you transfer anything that’s in the front end repeater to the “real” repeater.

  • Thanks @hube2!!

    I appreciate it!! That seems like a good solution!


  • Hi,
    i solve using acf/prepare_field

    I filter the repeater field always and dynamically i change the “max” attribute.


    function acf_limit_checkin_guest( $field ) {
    	global $wpdb;
    	$book_id = $_GET['wpseo_cf7_req_book_id'];
    	$guest = get_post_meta($book_id,"booking_guests",true);
    	$field['max'] = $guest-1;
        return $field;   
    add_filter('acf/prepare_field/key=field_60b76a6aba425', 'acf_limit_checkin_guest');
Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Dynamically set limit for repeater rows’ is closed to new replies.