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!


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

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.