Skip Navigation

[Resolved] Select2 Library

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to use select2.js in some of my site's custom code. I see that Toolset has its own select2.js dependency. Should I enqueue the library separately, or can I use the Toolset select2 feature?

Solution: At this time, it's best to enqueue the library separately.

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by mohammadD 6 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#623984

Hello
I am trying to use select2 library in the code below for creating custom search in my view.
I have seen that you have select2 library queued in the header. the path of this library is :
./types/vendor/toolset/toolset-common/res/lib/select2/select2.js?ver=4.0.3
I wanted to know how can i trigger it.
now I am using the select2 CDN , which i think is conflicting with yours.
here is my code for custom search and the js part.

[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
	<label>[wpml-string context="wpv-views"]Pol[/wpml-string]</label>
	[wpv-control-postmeta field="wpcf-ptp-pol" url_param="wpv-wpcf-ptp-pol"]
</div>
<div class="form-group">
	<label>[wpml-string context="wpv-views"]PoD[/wpml-string]</label>
	[wpv-control-postmeta field="wpcf-ptp-pod" url_param="wpv-wpcf-ptp-pod"]
</div>
<div class="form-group">
	<label>[wpml-string context="wpv-views"]Container Type[/wpml-string]</label>
	[wpv-control-postmeta field="wpcf-ppt-container-type" url_param="wpv-wpcf-ppt-container-type"]
</div>
[wpv-filter-submit output="bootstrap"]
[wpv-filter-spinner spinner="<em><u>hidden link</u></em>"][/wpv-filter-spinner]
[/wpv-filter-controls]
[wpv-filter-end]

and the js part :

$(document).ready(function() {
    $('.js-wpv-filter-trigger').select2();
});
#624068

Hi, let me ask my 2nd tier support team if we offer any best practices for integrating with select2.js. Can you tell me more about the conflict you mentioned? In a local test, I was able to enqueue select2 CSS and JS in a child theme and then call jQuery(...).select2() to initialize some select fields on the site. Is there a specific problem I can look at?

#624273

No i just wanted to make sure that i am not using something twice as the speed optimization is the most important thing to me.

#624637

After discussion with my 2nd tier team, it appears that enqueueing the library independently is your best option. No public API is available for utilizing the select2 library implemented by Toolset, and we do not recommend attempting to access it directly in your own custom code.

#624954

thanks