Support

Account

Home Forums Add-ons Repeater Field Would like my repeater field to be read-only

Solving

Would like my repeater field to be read-only

  • Hi guys, I’m doing an estate homepage and using Woocommerce for displaying the apartments as “products” – without the possibility to add to cart.

    The current scenario is, that I’ve created a form for the visitor to sign-up on a waiting list for the apartment if it is currently occupied.

    Every sign-up gets displayed as a new row in the backend, exactly as its supposed.
    However the user in backend, can edit the information submitted by the visitor, which I don’t like the possibility of.

    Can I do something to make all the subfields read-only or disable them somehow, so the backend user only can view the information submitted and delete rows (in case the first one on the list is offered the apartment)?

    Thanks in advance

  • hi @scwebstarters-dk

    You can use a filter to disable fields by name.. see an example below where I disable 2 fields… you can even disable by role/capabilities etc.

    
    <?php
    /* START: Makes the 'Customer Name' and 'Customer ID' fields in Users Read-Only */
    function cc_make_customer_name_and_id_fields_in_users_read_only( $field ) {
      $field['disabled'] = 1;
      return $field;
    }
    add_filter('acf/load_field/name=cc_customer_name_user', 'cc_make_customer_name_and_id_fields_in_users_read_only');
    add_filter('acf/load_field/name=cc_customer_id_user', 'cc_make_customer_name_and_id_fields_in_users_read_only');
    /* END: Makes the 'Customer Name' and 'Customer ID' fields in Users Read-Only */
    ?>

    More info on the filter used can be found here.

  • Hey @keithlock ,

    I’m jumping in here 5 years later because I discovered a glitch (maybe a JS conflict) while using the filter of your suggestion.

    Have a repeater field with a few subfields, try setting those input fields ‘disabled’ by add_filter (or even using a jquery script loaded in admin from your theme).
    Set a bunch of rows with dummy data into “hello world” post.
    Now try to drag and switch places between two rows, and update your post: sometimes data are literally switched between rows, sometimes rows disappear at all.
    Try also to start over, this time delete one row from top or middle of the group, and update post again: the row you chosed to remove is still there while the last one of the group has gone.

    I made some tests and the glitch seems to stop when I stop keeping fields ‘disabled’.
    I’d love to offer a brilliant solution as well, but I’m not skilled enough.

    Have you got some suggestion how to solve this?

    I just found out why that happened and how to avoid this behaviour, here:
    https://support.advancedcustomfields.com/forums/topic/disabled-readonly-field-in-repeater/#post-68179

    set the field to “readonly” (required to avoid weird reaction of ACF when trying to save a JS disabled input)

    please note that disabled field are not saved and it is better to use radonly to keep your data

    Hope this helps someone in the near future. 🙂

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

The topic ‘Would like my repeater field to be read-only’ is closed to new replies.