Support

Account

Home Forums Feature Requests Repeater: Step Size

Helping

Repeater: Step Size

  • Hey ACF Team,

    Had another idea this morning. Sometimes I use the repeater field for rows of content (like rows of 3 image blocks or something, let’s just say)… it would be cool to have a “step size” (for lack of better term)… where you can specify if they want to add more, how many more it HAS to add.

    So, for instance, if you set it to 3, everytime they clicked “Add Row” it added 3 at a time (if that’s what you were going for).

    Does that make sense?

    Of course, you can fake this by just having three required fields INSIDE the repeater field, so when you click add Row it adds all three… so maybe I haven’t thought this all the way through, what do you think?

  • I don’t think this is something that I’d use. I don’t generally subscribe to creating absolute limits and go by this rule https://en.wikipedia.org/wiki/Zero_one_infinity_rule. For example, what if on a medium size device you want to have rows of 2 instead of 3, before stacking them all on really small devices. I think that the developer would consider something like this an “edge case”.

    This could be done with some creative JavaScript. I have an example here that deletes and automatically creates rows in a repeater https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-repeater-on-category and this topic discusses adding a confirmation before deleting a layout in a flex field that could probably be adapted to a repeater field https://support.advancedcustomfields.com/forums/topic/add-remove-field-confirmation-dialog/

    You could detect when a row is appended, count the current rows and then add enough to make it a number that is a multiple of the number you want. You could also probably detect when one is deleted, add a confirmation and then remove that number of rows. The problem here would be, which of the others to you delete. Your client might be pissed if you arbitrarily delete the ones they want to keep.

    A better (and probably simpler) solution might be to create an acf/validate_value filter https://www.advancedcustomfields.com/resources/acf-validate_value/ for the repeater field and count the number of rows submitted and return an error if it does not match what is needed.

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

You must be logged in to reply to this topic.