Support

Account

Home Forums Backend Issues (wp-admin) Setting all other true/false fields to false when repeater field is toggled

Solved

Setting all other true/false fields to false when repeater field is toggled

  • I have a repeater field that includes a true/false toggle called featured_item. On any given post where this repeater lives, I only want one of the repeater rows to be able to have this toggled to true in the edit post admin section. If the admin goes in and toggles this field to true and there is already an existing row that has this field enabled, I would like for the new row to be enabled and the other row to be disabled, so that there’s only ever one row on the page with the true/false field enabled.

    The other challenge is that this repeater is nested within another repeater, but only one true/false field on the entire post should be allowed to be enabled at any given time. I am thinking there’s probably a way this can be done with the save_post filter, but I’m not sure where to start. I would also be open to using a JavaScript solution.

    Can anyone point me in the right direction?

  • This should work, but I’m not 100% sure on that. I wrote it many years ago.

    https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/unique-repeater-checkbox

    It should affect all fields with the same field key on the page no matter where they are.

  • This worked perfectly, thank you! I used the acf57 version of the JS and made one minor adjustment, since I am using “Stylized UI” for the field, to remove the -on class from the toggle that gets disabled.

    Appreciate it!

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

You must be logged in to reply to this topic.