Support

Account

Home Forums General Issues Prevent AJAX loading for taxonomy select fields

Solving

Prevent AJAX loading for taxonomy select fields

  • Is there any way to turn off the loading of values for taxonomy select fields?

    I have a form with a number of fields which get their values from taxonomies, but the taxonomies only have a few values, so there’s little if any performance benefit from loading the values with ajax, and a significant user delay for every select field since it takes a couple of seconds to see the values on clicking the select field.

    Ideally I would like to have all the values pre-loaded in PHP – in the same way a select field with manually set values loads if the ajax option is turned off. Is there a way to do that?

    If that’s not possible, is there any way to tell select2 to load the values for all select fields as soon as the page has loaded – before the user has to click anything?

  • If you’re trying to get this to the developer then you need to open a new support ticket. https://support.advancedcustomfields.com/new-ticket/.

    All of these type of fields, like you say, use select2. I don’t know if you can tell select2 to load all the fields ahead of time or not, I don’t know all that much about select2. If you can it would be done though adding a filter in javascript for the select2_init action documented on this page https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/.

  • Thanks John. The select2_init javascript hook might do the trick, but I’m not sure what to call… I’ll open a ticket and see what’s possible.

  • There is not a lot of documentation on the JS in ACF, I’d do a search of Select2 to see what I could find, but I’m not even sure what to search for, or if there is an action you can trigger in the acf code to force the select2 field to load when the page loads.

    Also, you might want to look at the possibility of using a plain old select field that is dynamically loaded with choices https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/

  • I could dynamically load a select field, but unfortunately I’m already using some of the specific taxonomy field features in multiple places in my code (e.g. saving tax terms, using get_field to get full term object etc) so it would involve a fair bit of refactoring.

    Support suggested the same thing, or that I could create my own field type which would mean I don’t need to refactor any existing code.

    Either way looks like solving this will involve a fair bit of (re)coding 🙁 but at least I’m not missing something obvious.

    Thanks for your help.

  • Rather than create a custom field type, use a select field and create a format value filter for the field to return the same thing that ACF returns for a taxonomy field. This would let you change the field type without altering any of the code where the current field is used and let you keep using it the same way. https://www.advancedcustomfields.com/resources/acfformat_value/ Probably a lot less coding than either of the other choices?

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

The topic ‘Prevent AJAX loading for taxonomy select fields’ is closed to new replies.