Custom Fields
Re-Envisioned
Support General Select2 error, possible conflict with The Events Calendar

This topic contains 2 replies, has 2 voices, and was last updated by  Stefan Grassberger 3 weeks, 2 days ago.

  • Creator
    Topic
  • #16643
    Resolved
    Stefan Grassberger
    Participant

    On a client site we use:
    Meta Box 5.2.2
    MB Relationships 1.7.0
    The Events Calendar 4.9.10

    When editing an event (classic editor), the select dropdown in the relationship meta box fails to load posts (no entries). This is the error in the browser console:

    Error: Option 'ajax' is not allowed for Select2 when attached to a <select> element. 2 select2.min.js:21:18425
        prepareOpts http://localhost/wp-content/plugins/the-events-calendar/common/vendor/tribe-select2/select2.min.js:21
        each jQuery
        prepareOpts http://localhost/wp-content/plugins/the-events-calendar/common/vendor/tribe-select2/select2.min.js:21
        prepareOpts http://localhost/wp-content/plugins/the-events-calendar/common/vendor/tribe-select2/select2.min.js:22
        init http://localhost/wp-content/plugins/the-events-calendar/common/vendor/tribe-select2/select2.min.js:21
        select2 http://localhost/wp-content/plugins/the-events-calendar/common/vendor/tribe-select2/select2.min.js:22
        jQuery 2
        select2 http://localhost/wp-content/plugins/the-events-calendar/common/vendor/tribe-select2/select2.min.js:22
        transform http://localhost/wp-content/plugins/meta-box/js/select-advanced.js:92
        jQuery 8
        clone http://localhost/wp-content/plugins/meta-box/js/clone.js:154
        addClone http://localhost/wp-content/plugins/meta-box/js/clone.js:196
        jQuery 2

    On other post edit screens (classic editor), the relationship drop down works fine. I think the Select2 script gets loaded by both The Events Calendar and Meta Box and this is could be the cause of the error?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #16650

    Anh Tran
    Keymaster

    Hi Stefan,

    The problem is TEC uses an older version of select2 (3.x) while Meta Box uses version 4. Searching on the Internet shows quite a lot of similar problems and the solution is use only one version of select2.

    In this case, I think to make it work again, it’s required to not using select2 from Meta Box. You can do that by switch the field type from select_advanced to normal select like this:

    add_action( 'mb_relationships_init', function () {
        MB_Relationships_API::register(
            array(
                'id'   => 'posts_to_pages',
                'from' => [
                    'field' => [
                        'post_type'  => 'post',
                        'ajax'       => false,
                        'field_type' => 'select',
                        'query_args' => array(
                            'posts_per_page' => -1,
                        ),
                    ],
                ],
                'to'   => [
                    'field' => [
                        'post_type'  => 'tribe_events',
                        'ajax'       => false,
                        'field_type' => 'select',
                        'query_args' => array(
                            'posts_per_page' => -1,
                        ),
                    ],
                ],
            )
        );
    } );
    #16655

    Stefan Grassberger
    Participant

    Hi,
    thank you for the workaround, I can confirm this works! I also tried disabling the select2 script loaded by TEC, but that breaks the selection of venues and organizers in their meta box. I guess TEC need to update their select2 version to 4.x as well.
    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.