Integrating the Select2 JavaScript library into Lightning Components

Let's take another open source JavaScript library, Select2 (https://select2.Org/), which provides functionality to autocomplete and allow the user to add multiple selections to an input.

The source code for this library can be downloaded from the Select2 Git repository (https://github.com/select2/select2/releases).

The example HTML code to integrate Select2, giving us the ability to add multiple choices to the input, is as follows:

<html>  <head>    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" type="text/css">    <script type="text/javascript" src="jquery.js"></script>  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script> ...

Get Learning Salesforce Lightning Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.