Select2 – A better autocomplete widget

At the end of June, we as the Thunder Core Team, decided that we want to have a select2 widget as a drop-in replacement for Drupal's Autocomplete widget in Thunder. Furthermore, since we are currently working on a search integration, we also wanted to have a select2 widget that could be used as a facet. We started to look for Drupal 8 select2 implementations and found two existing modules.

The first select2boxes, is far too bloated with features that we didn’t need, and it also does not separate its functionality in a render element and a field widget. All the code is in the field widget plugin. That meant to us, for example, that there is no way to re-use functionality in a facet widget. The second module we looked at was select2 widget, it didn’t fulfill our needs as well and, furthermore, it has had zero activity since February. We cannot rely on an unmaintained module for Thunder.  

After all, we decided to develop a new select2 module for Drupal 8 with some principles in mind:

•    Clear separation of render element and field widget code.

•    It should be possible to use the select2 widget as a normal form element.

•    The main module should only contain code that is needed to make the field widget functional. Additional functionality should be added in sub-modules  

Now, after 3 months of work, we now have a select2 module in beta stadium that will soon enter RC phase and become stable. We are using the module already in Thunder for a while and it works perfectly for us.

Some of the key features are:

•    Autocompletion: On entity reference fields the widget can act as the core autocomplete widget and does not load all referenceable entities on a page load.

•    Autocreation: If enabled on the field settings, it’s possible to create new entities on the fly.

•    Internationalization: The select2 widget supports a lot of languages and has also RTL support.

•    Integration with the ‘Thunder Admin’ theme: The default select2 style was adopted to fit better into the ‘Thunder Admin’ look and feel and there are also adopted styles to fit into Drupal seven theme.

•    Facet widget: Within a sub-module, a facet widget is shipped.

•    Status indication: The select2_publish sub-module provides CSS classes on referenceable entities to indicate the publish status. 

 

We therefore encourage every one of you to try it out and give us some feedback.