Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

Virtual Select

3 sites Security covered
View on drupal.org

This module integrates a JavaScript library to enhance select form elements, allowing for a large number of options, multi-select functionality, and a search feature. It provides a more performant and user-friendly way to handle complex dropdowns.

Provides an integration with the Virtual Select library for select form elements.

Features

  • Support more than 100.000 dropdown options.
  • Support multi-select.
  • Support search feature.

Dependencies

This module requires you to install the JavaScript library Virtual Select.

Installation

You can install the module like any other Drupal module. For more information, please consult https://www.drupal.org/docs/extending-drupal/installing-modules.

Composer

It is recommended to install the Virtual Select JavaScript library with Composer.

In the require section of your composer.json, add the virtual-select-plugin JavaScript library.

"require": {
    "drupal/virtual_select": "^1.0.0",
    "npm-asset/virtual-select-plugin": "^1.0.38"
}

In the repositories section of your composer.json, add the asset-packagist repository.

"repositories": [
    {
        "type": "composer",
        "url": "https://asset-packagist.org"
    }
],

In the installer-types section of your composer.json, add the npm-asset type.

"installer-types": [
    "bower-asset",
    "npm-asset"
],

In the installer-paths section of your composer.json, add the virtual select library.

"web/libraries/{$name}": [
    "type:drupal-library",
    "npm-asset/virtual-select-plugin"
],
"vendor/npm-asset/{$name}": [
    "type:npm-asset"
],

Usage

This module provides an implementation for @FormElement and @FieldWidget. You can use the element like any other form element. For more information, please consult https://api.drupal.org/api/drupal/elements.

Example

$form['virtual_select'] = [
  '#type' => 'virtual_select',
  '#title' => $this->t('My Virtual Select element'),
  '#options' => [
    'cheese' => $this->t('Cheese'),
    'eggs' => $this->t('Eggs'),
    'milk' => $this->t('Milk'),
    'rice' => $this->t('Rice'),
    'chicken' => $this->t('Chicken'),
    'bread' => $this->t('Bread'),
  ],
  '#default_value' => ['chicken', 'milk'],
  '#multiple' => TRUE,
  '#placeholder' => $this->t('- Select -'),
  '#search' => TRUE,
  '#show_value_as_tags' => TRUE,
  '#show_selected_options_first' => TRUE,
  '#search_placeholder' => $this->t('Search...'),
  '#show_options_only_on_search' => FALSE,
  '#no_options_text' => $this->t('No options found.'),
  '#select_all_text' => $this->t('Select all'),
  '#all_options_selected_text' => $this->t('All'),
  '#disabled_options' => ['rice', 'bread'],
];

Activity

Total releases
1
First release
Jul 2025
Latest release
11 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Slowing

Releases

Version Type Release date
1.0.1 Stable Jul 26, 2025