I followed the Example 2 on the link below and everything works well.
I’m able to check the boxes I want and then display it on the front-end. My issue is if I update the value of the checkbox, it becomes unchecked when I go back to the page. If I inspect the checkbox I can see that when I change the value, the ID changes too.
Is there anyway to do it so if I update the value of the checkbox in the admin, that it doesn’t uncheck the checkbox on the page but yet just update the value?
Thanks in advance!
Using the document you followed should not result in the effect that you state
the ID changes too
Can you give a clearer picture of what is happening because I don’t think I’m following your explanation.
Thanks for the response. Using the example above, if I update the value field, the checkbox becomes unchecked. If I just update the label, it stays checked.
Ideally I wouldn’t have 2 fields and just have 1 that the client can update in Options and then the available checkbox is updated without being unchecked after it’s updated.
I hope that makes more sense.
Thanks so much!
Was my last post a clearer picture?
I cannot access the images that you linked to.
If you copy the links and paste in the browser, they load fine.
Let me see if I understand what is happening.
You are dynamically populating the values of a select field from the values of the repeater field.
You make a change to the repeater field that changes a selected value and this causes whatever was selected in the select field to become unselected.
If this is the case then there isn’t any way to do what you want using what you have. Since the old value does not exist ACF does not know what to set as selected. The value is missing.
Your option are:
1) Do not remove values that have been previously selected.’
2) Set the value of the select field to the repeater row position instead of the sub field value and then when using the fields on the front of the site look up that position in the repeater to get the value
3) Create a 3rd field in the repeater for a key that will never be changed and use that for the value. Then look up that key in the repeater to use on the front end. This is just like option 2 but it allows you more control to do things like alter the order of the repeater rows without changing values.
Thank you very much!
I think #3 is my best option. I really appreciate your time.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2021 Advanced Custom Fields. Subscribe