Support » Plugin: Max Mega Menu » Widgets with ACF fields select2 not rendering

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author megamenu

    (@megamenu)

    Hi argendejong,

    Please can you check if the (correct) select2.js script is being loaded in the page source of the nav-menus.php page? If it is being loaded, check there are not 2 copies being loaded (one from ACF, one from another plugin).

    If only one copy is being loaded, can you also check if there are any JS errors in the console when you click the blue mega menu button?

    Failing that, I am not all that familiar with ACF, so (assuming it is possible with the free version) I will need instructions on how to replicate the issue locally (i.e. how do I create one of those widgets myself).

    Thread Starter arjendejong

    (@arjendejong)

    Hey,

    There’s only one select2 script being loaded (from WooCommerce) (select2 v4). ACF Pro loads the single select2 style. The console gives no errors, only: “admin.js?ver=2.5.3.2:16 Launched for Menu ID 10376” when clicking the blue button.

    Here’s how I created the widget (functions.php). And here’s the JSON for the ACF field. Have ACF (pro) and WooCommerce installed. Thanks for helping me!

    Plugin Author megamenu

    (@megamenu)

    Hi aejendejong,

    Thanks.

    It sounds like a conflict between the select2 scrips. ACF may be using one version, and WooCommerce another. Can you try disabling WooCommwerce so that only the ACF scripts are loaded?

    Thread Starter arjendejong

    (@arjendejong)

    Hey,

    I found something interesting. When disabling select2 from all plugins, on the widgets.php page I immediately get an error from acf-input.js saying select2 is not a function (which is clear because we disabled it) but that error does not appear when I open the widget in Mega Menu in nav-menus.php. https://imgur.com/WDLezwy However, when I click on the reload button in Chrome, the error appears in the console before vanishing because the page got reloaded. When I enable select2 again, on clicking reload, I can see the select transforming into a select2. When I immediately click the reload button again, stopping the browser from reloading the page, I can do everything with that field like I’m supposed to. It seems that something is preventing ACF from transforming the select into a select2 field. The script can only execute when reloading the page. Do you have any insight on this? Can you tell me if this behaviour also happens at your end?

    Thread Starter arjendejong

    (@arjendejong)

    I’ve fixed this by adding the following at the end of the success function of the $.post function in js/admin.js:1055

    if ('acf' in window) {
        acf.getFields(document);
    }

    This assumes that you have ACF loaded. Would it be possible to integrate this into your plugin? Or do you know a way to put this piece of code in my theme?

    Plugin Author megamenu

    (@megamenu)

    Hi arjendejong,

    I have purchased a copy of ACF Pro so I can replicate/test this (although I think it turns out I did not need to do this). Many thanks for the clear descriptions (and the ACF json file) and solution – I’ve committed it here:

    https://plugins.trac.wordpress.org/changeset/2020380

    It will be included in the next update, so you can leave your manual edit in place and then update normally once the next update is released.

    Thread Starter arjendejong

    (@arjendejong)

    That’s awesome news! Glad it got integrated inside the plugin!

    It seems that acf-input.js only loads the content in the DOM once when loading the page. It does not account for content coming in via a call to admin-ajax.php. That’s where my ‘fix’ comes in. It retrieves all fields again, including the ones from admin-ajax.php.

    • This reply was modified 2 years, 10 months ago by arjendejong.
    • This reply was modified 2 years, 10 months ago by arjendejong.
    • This reply was modified 2 years, 10 months ago by arjendejong.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Widgets with ACF fields select2 not rendering’ is closed to new replies.