Skip Navigation

[Résolu] select box select2 plugin

This support ticket is created Il y a 2 années et 5 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 réponses, has 2 voix.

Last updated by davidm-13 Il y a 2 années et 5 mois.

Assisted by: Shane.

Auteur
Publications
#2204111

Hi, I have some select dropdown list on my site - florapal.org - and I'd like to add autocomplete to filter results from the lists.

I saw this thread https://toolset.com/forums/topic/split-how-to-convert-a-normal-dropdown-to-a-select2-dropdown/ from Nigel and would like instruction on how to install and use select2 on my site.

Also interested if you can suggest better alternatives to implement autocomplete to search select dropdown lists

Thanks very much for any help

#2205353

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for getting in touch.

This one might be tricky to implement and I cant guarantee that it will work as we're using 3rd party libraries. Also we don't know what negative effects this will have on your site such as with compatibility.
hidden link

First thing you'll need to do is to import the scripts to your site. On the select2 website above you will see the CDN link for the files are

<link href="<em><u>hidden link</u></em>" rel="stylesheet" />
<script src="<em><u>hidden link</u></em>"></script>

However you will need to enqueue these using the wordpress function for importing scripts to your site. Add these to your functions.php file.


wp_enqueue_style( 'select2_css', '<em><u>hidden link</u></em>' );
    wp_enqueue_script( 'select2_script','<em><u>hidden link</u></em>' );

Once you've done this and can confirm on the frontend of the site that these scripts have been imported then its time to run the function to convert the select into select2

$(document).ready(function() {
    jQuery('.css-class-goes-here').select2();
});

Now all you need to do is add the css class of your select field to the jQuery above. The class can be found by using the developer tools on your browser to inspect the select field.

Please let me know if this helps.
Thanks,
Shane

#2205481

My issue is resolved now. Thank you!
Hi Shane, I was having problems implementing autocomplete using "Chosen for WordPress" - which is why I wanted to try Select2 - but now I think I've sorted the problem with Chosen so I'll stick with that.
Thanks for your help

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.