Support

Account

Home Forums Backend Issues (wp-admin) Updating the select field choices becomes unchecked

Solving

Updating the select field choices becomes unchecked

  • Hi all,

    I followed the Example 2 on the link below and everything works well.

    https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/

    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.
    ‘id=”acf-field_6065d9ae539f7-Color1-value”‘

    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!

    Robb

  • 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.

  • Hi John,

    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.

    http://v23dev.com/online/pic1.png
    http://v23dev.com/online/pic2.png

    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!

  • Hi John,

    Was my last post a clearer picture?

    Thanks!
    Robb

  • I cannot access the images that you linked to.

  • Hi John,

    If you copy the links and paste in the browser, they load fine.

    Thanks!

  • 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.

  • Hi John,

    Thank you very much!

    I think #3 is my best option. I really appreciate your time.

    Thanks!
    Robb

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

You must be logged in to reply to this topic.