On my website I have relationship field where many options are available to choose. In case that an user with a specific role is logged in and wants to create a new post (where the relationship field is placed) the user only sees options in that relationship fields which belongs to his user account. This is already working fine. But in case that there is only one option available in the relationship field, this option needs to be selected automatically. Before a few days, it was working on ACF 4.9.X. After upgrading that page to the current version of ACF this mechanic is not working anymore. I don’t know how it was done but I tried to find appropriate solution for the current version of ACF.
One obvious change regarding to the version 4.9.X is that the available options in the relationship field are only loaded via ajax when the field becomes visible in viewport.
So what I need is probably a JS event, which is called when the ajax call of the relationship field is done and the result is placed in the frontend. Then I would check if there is only one item in the list of available options and afterwards I would select it. I would try this by using a “.click()” trigger on the first result but if there is a more charming solution for selecting the only available option, I would be happy if you could show it to me :-).
I hope you can help me at this point!
Viewing 1 post (of 1 total)
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
2022 was a big year for Advanced Custom Fields, with more capabilities, a new generation of ACF Blocks, a refreshed UI, and a new home. Our year in review post looks at advancements we’ve made and offers a glimpse of the future. https://t.co/HahJUCcyH4