How it works…

This plugin is not specifically intended for Bootstrap, but it fits perfectly. Its setup was really easy, as the plugin can be readily included in some popular CDNs.

To make it work with bootstrap, all we had to do is wrap it in <div class="form-group">. For improved styling, we added the class of form-control onto the select element.

To run the plugin, all we had to do is target its specific class, and then pass in an object of options to the select2 method. In the options object, we passed in the placeholder key and its custom string value, and the allowClear key and its Boolean value.

Get Bootstrap 4 Cookbook 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.