Support

Account

Home Forums Bug Reports Select2 in repeater broken after update to 5.5.13

Solving

Select2 in repeater broken after update to 5.5.13

  • After updating ACF Pro to 5.5.13 we’re no longer able to add repeater rows containing post objects.

    We’re updating from 5.5.11, and have not tested on 5.5.12.

    This is the console error we’re getting:

    select2.full.min.js?ver=4.0.3:3 The select2('destroy') method was called on an element that is not using Select2.

    select2.full.min.js?ver=4.0.3:3 Uncaught TypeError: Cannot read property 'destroy' of undefined
        at HTMLSelectElement.<anonymous> (select2.full.min.js?ver=4.0.3:3)
        at Function.each (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery…:2)
        at a.fn.init.each (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery…:2)
        at a.fn.init.a.fn.select2 (select2.full.min.js?ver=4.0.3:3)
        at Object.destroy (acf-input.min.js?ver=5.5.13:2)
        at Object.do_function (acf-input.min.js?ver=5.5.13:2)
        at Object.destroy (acf-input.min.js?ver=5.5.13:2)
        at Object.remove (acf-input.min.js?ver=5.5.13:2)
        at acf-input.min.js?ver=5.5.13:1
        at d (acf-input.min.js?ver=5.5.13:1)
  • Same JS error for me too using 5.5.13. But I am using a Flexible Content field. And the issue seems to any layout with a clone field.

    I get the error when trying to “add new layout” in the custom fields editor. I get the same error when using the layout button to add a layout to a page if it’s any of my layouts with the clone field.

    UPDATE: I tried rolling back to 5.5.11, but it still doesn’t work. Which is weird because it did work at some point, I had the layout added to my page that I can no longer add.

    NOTE: Download link for 5.5.12 looks to be actually v5.5.13

  • Note, I am happy to provide full access to a staging site to help triage this, it’s a pretty mission critical bug for me. Thanks!!

  • Same problem here when I try to add a flexible content block that uses a field clone. ACF v5.5.13

    
    Uncaught TypeError: Cannot read property 'destroy' of undefined
        at HTMLSelectElement.<anonymous> (select2.full.min.js?ver=4.0.3:3)
        at Function.each (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery…:2)
        at a.fn.init.each (load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery…:2)
        at a.fn.init.a.fn.select2 (select2.full.min.js?ver=4.0.3:3)
        at Object.destroy (acf-input.min.js?ver=5.5.13:2)
        at Object.do_function (acf-input.min.js?ver=5.5.13:2)
        at Object.destroy (acf-input.min.js?ver=5.5.13:2)
        at Object.remove (acf-input.min.js?ver=5.5.13:2)
        at acf-input.min.js?ver=5.5.13:1
        at d (acf-input.min.js?ver=5.5.13:1)
  • Yeah, this has caused some pretty major errors on one my sites (in production).

    I dug into the console a little and saw that the select2.min.js file was actually being called from the Yoast SEO plugin folder. I then deactivated Yoast and found Woocommerce causing the exact same issue. Once I deactivated Woocommerce ACF started working as expected.

  • I was going to say that this appears to be a conflict with another plugin. More than likely due to multiple versions of select2. The first plugin that registers/enqueues the script wins in WP. I would suggest opening a new support ticket here if you haven’t already https://support.advancedcustomfields.com/new-ticket/ and also reporting the trouble to the other plugins as well.

  • yes, you’re right. thanks for the hint. In my case it was woocommerce that was in conflict.

  • I do know that ACF uses an older version of select2 and for specific reasons, like there is functionality missing from the new version that is used by ACF. From my experience, 99.9% of the time the plugins that use the new version will work on the older version. The solution is usually to either prevent the other plugin from enqueuing its version of select2 or to dequeue/unregister it so that ACF can enqueue it’s version, but I don’t know the exact solution for any of the plugins that have this problem.

  • It would seem to me that if ACF are using an outdated copy of Select2 and if that is the cause of the conflict then ACF either needs to isolate the plugin somehow or find a way to bring it up to date. The other plugins using Select2 all seem to play fine together – it’s just ACF having trouble since the latest update.

  • Like I said, ACF uses an older version because some of the functionality from the old version has not been ported to the new version, and it’s functionality that many ACF users would likely be upset to loose. As far as updating ACF, you’d need to take that up with the developer by opening a support ticket, I’m sure that the developer can explain better than I can why he’s still using the old version.

    https://support.advancedcustomfields.com/new-ticket/

  • Thanks John. I’d opened a ticket before replying to this thread. Apparently a patch might be ready (according to the response I’ve had so far)

  • There is a way to have ACF use the new version of select2, but I don’t know what consequences or side effects this will have.

    
    add_filter('acf/settings/select2_version', 'make_acf_use_select2_4');
    function make_acf_use_select2_4($version) {
      return 4;
    }
    
  • Thanks John. That’s fixed the problem for now.

  • This is still an issue..
    Shall I disable Woo with 200+ products to use ACF or shall I scream ?

  • Did you try adding the filter I posted above to your site?

  • return 2; to make it work, and thank you 🙂 kindly.. but should work without filter, a

  • The filter did not work for me. I’m still getting the same errors. I tried both return 4; and return 2;.

  • Same here, I applied the filter but nothing changed. @jolora you were talking about a patch that might be ready. Do you have information on when this could be released?

  • Apparently it’s just a case of the devs uploading it. I assume there are other fixes/improvements going into the same update that still need finishing.

    However, if changing the select2 version didn’t help are you sure that it’s down to a conflict with other plugins?

  • I am not sure, but it seems like that is the case. The error references the select2 file from the WordPress SEO folder, when disabling that plugin, the same error references the select2 file from the Woocommerce folder. When disabling Woocommerce there are no errors.

  • For anyone still having a problem, I would suggest again to submit a support ticket.

    https://support.advancedcustomfields.com/new-ticket/

    Until there is an official fix we will need to use work-a-rounds.

    There is the filter I posted above.

    You can also figure out how to dequeue the select2 version in the other plugins so that ACF can register it’s version but I cannot give you specific information on how to do this at the moment, because I don’t know.

  • Just to add some more data for what works and doesn’t:

    – the acf/settings/select2_version filter doesn’t help
    – I also tried acf_update_setting('select2_version', 4 ); which didn’t work either
    – I am using WooCommerce, and it’s WC’s select2 which gets enqueued
    – when attempting to add a new repeating field set in a form in admin I get the same js error as reported by others
    – reverting to ACF 5.5.11 resolves the issue

  • I have the exact same scenario as rowatt, and can confirm that the only thing working for me as well was to downgrade ACF to 5.5.11

  • @jolora I cannot recreate an issue using the latest version of yoast when only it and ACF are installed. With yoast and WC installed, I do see the same error, but just deactivating WC clears up this issue. Only discovered this when trying to find a solution for yoast being a problem.

    I’m trying to figure out a better solution since what I posted does not seem to work for everyone. I’ll see what I can find with WC.

  • I’m pretty sure that it all comes down to the order in which the scripts are enqueued, and I can’t for the life of me figure out why the script in one plugin is loaded before the script in another plugin. All of the plugins in question use a priority of 10 for admin_enqueue_scripts.

    This is the best I could figure out as a temporary corrective action. Force the ACF version to be enqueued first

    
    
    add_action('admin_enqueue_scripts', 'early_enqueue_acf_select2', -999);
    function early_enqueue_acf_select2() {
    	$min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
    	$script = acf_get_dir("assets/inc/select2/3/select2{$min}.js");
    	$style = acf_get_dir("assets/inc/select2/3/select2.css");
    	$version = '3.5.2';
    	wp_enqueue_script('select2', $script, array('jquery'), $version );
    	wp_enqueue_style('select2', $style, '', $version );
    }
    

    Is it a perfect solution, nope, but it will due for me until Elliot gets this sorted out, or some other issue is found. If anyone has the time to kill and the ability to test this I’d like to know it this causes any issues with either ACF or WC because I have at least one site I know of that’s using both. I’ve done some testing on a dev site and things appear to be working, but I wouldn’t mind having confirmation before I update a live site.

Viewing 25 posts - 1 through 25 (of 30 total)

The topic ‘Select2 in repeater broken after update to 5.5.13’ is closed to new replies.