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
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
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.