Support

Account

Home Forums ACF PRO Hide already filled in rows in ACF_Form

Solving

Hide already filled in rows in ACF_Form

  • Hi all,
    I’m using an ACF_FORM to display a repeater field where a visitor can add a new row and fill that in.
    Okay.
    The default behaviour of a repeater field on the front-end (with an ACF_FORM) is that all filled-in rows are shown, and that all rows are editable.
    But I want the previously added rows hidden to the visitor, so they can not be edited anymore.
    For now I’ve done this with a simple, yet very smart (haha), snippet of CSS:

    tbody tr.acf-row:not(:nth-last-child(-n+2)) {
    	display: none;
    }

    What this does is hiding all the rows with class=”acf-row” except for the last 2.
    “Why 2?” you may ask.
    Well, the very last row is hidden by default and is used when the visitor clicks the ‘Add Row’ button. The second to last row is in fact the last filled-in row.

    This works but, to be honest, I have mixed feelings when such things are done with CSS.
    So, is there a way to do this with a hook or filter or something else?

  • Not really. The best work around that I can think of would be to have 2 repeater fields, one that is shown in the acf_form and one that is not shown. You’d need to specify in your call to acf_form() which fields that you want to show. Then create an acf/save_post filter to move the new new values into the first repeater and delete the new values from the second repeater that’s their for just the front end form.

  • Hi John,
    Good thinking!
    In fact, it is almost the same as putting a generic form (no ACF_FORM) on the front-end with the appropriate fields and store the collected input in the repeater where it belongs.
    Either way, I like this approach.
    Thanks!

  • You could have to different field groups, that that’s shown on the user side and one that’s shown on the admin site. Then using an acf/save_post filter copy the values to the admin field group and delete things from the user field group if you need to. I created a custom location rule a while back that let’s you include field groups base on whether it’s on an admin or front end page. https://github.com/Hube2/acf-filters-and-functions/blob/master/is_admin-acf-location-rule.php

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

The topic ‘Hide already filled in rows in ACF_Form’ is closed to new replies.