Select2 error, possible conflict with The Events Calendar
- This topic has 2 replies, 2 voices, and was last updated 5 years, 6 months ago by
Stefan Grassberger.
-
AuthorPosts
-
October 21, 2019 at 10:31 PM #16643
Stefan Grassberger
ParticipantOn a client site we use:
Meta Box 5.2.2
MB Relationships 1.7.0
The Events Calendar 4.9.10When 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?
October 22, 2019 at 10:33 AM #16650Anh Tran
KeymasterHi 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 normalselect
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, ), ], ], ) ); } );
October 22, 2019 at 5:17 PM #16655Stefan Grassberger
ParticipantHi,
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! -
AuthorPosts
- You must be logged in to reply to this topic.