I’ve used the same select2 version 3.x which ACF uses in the backend in my theme and I can just update the actual <option> tags inside <select> tags with prop(‘disable’, true) on the <option> tags and then trigger(‘update’) on the <select> tag, that makes select2 update its view and show the disabled options correctly.
But the same does not work for the ACF fields which uses select2, any idea why? and how can I make it work?
I’m afraid you can’t disable the options. But you can always modify the returned data by using the
acf/load_field hook. That way you can remove the options you want. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/
I hope this helps 🙂
I’m afraid that wont work for me, I need to limit options of selectbox 2 based on the choice selected in selectbox 1.
What you have mentioned above would require updating the post. I got several dependent fields like this, forcing a page refresh on updating a field value would not be a good experience to the person doing the data entry.
In that case, I think you can try this tutorial: https://www.bobz.co/dynamically-populate-select-fields-choice-in-advanced-custom-fields/.
It’s an old tutorial, but I believe you still can use it.
Hope this helps 🙂
Update 1 :
select2_args might be usable
Thanks for the link but that tutorial is using native select boxes, with multiselect enables those can be a problem (accidental clicks, without pressing ctrl etc, just really annoying) 😛
I’ll give the select2_args idea I had a try and update here if it works as expected.
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!
📣 “ACF Chat Fridays”— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 2023 Advanced Custom Fields.