PHPackages                             silverware/select2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. silverware/select2

ActiveSilverstripe-vendormodule

silverware/select2
==================

SilverWare Select2 Module.

1.2.0(7y ago)514.5k6[4 issues](https://github.com/praxisnetau/silverware-select2/issues)[1 PRs](https://github.com/praxisnetau/silverware-select2/pulls)2BSD-3-ClausePHPPHP &gt;=5.6.0

Since Sep 6Pushed 7y ago2 watchersCompare

[ Source](https://github.com/praxisnetau/silverware-select2)[ Packagist](https://packagist.org/packages/silverware/select2)[ Docs](https://github.com/praxisnetau/silverware-select2)[ RSS](/packages/silverware-select2/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (7)Dependencies (1)Versions (10)Used By (2)

SilverWare Select2 Module
=========================

[](#silverware-select2-module)

[![Latest Stable Version](https://camo.githubusercontent.com/1fc41a1d32a4eb169ed971d5ba25af89c1a109e3584fa78b7bda3df2fba31311/68747470733a2f2f706f7365722e707567782e6f72672f73696c766572776172652f73656c656374322f762f737461626c65)](https://packagist.org/packages/silverware/select2)[![Latest Unstable Version](https://camo.githubusercontent.com/66ef0599eb5e32f12fcfca8576860bfe653fe58ad07482d050c799762a9c52d4/68747470733a2f2f706f7365722e707567782e6f72672f73696c766572776172652f73656c656374322f762f756e737461626c65)](https://packagist.org/packages/silverware/select2)[![License](https://camo.githubusercontent.com/3d29516978b9a9874486a41acd2851f8a3bbd469cc844a487581669c2c171f6d/68747470733a2f2f706f7365722e707567782e6f72672f73696c766572776172652f73656c656374322f6c6963656e7365)](https://packagist.org/packages/silverware/select2)

Provides Select2-powered dropdown and Ajax fields for [SilverStripe v4](https://github.com/silverstripe/silverstripe-framework). Intended to be used with [SilverWare](https://github.com/praxisnetau/silverware), however this module can also be installed into a regular SilverStripe v4 project.

Contents
--------

[](#contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Issues](#issues)
- [Contribution](#contribution)
- [Attribution](#attribution)
- [Maintainers](#maintainers)
- [License](#license)

Requirements
------------

[](#requirements)

- [SilverStripe Framework v4](https://github.com/silverstripe/silverstripe-framework)

Installation
------------

[](#installation)

Installation is via [Composer](https://getcomposer.org):

```
$ composer require silverware/select2

```

Configuration
-------------

[](#configuration)

As with all SilverStripe modules, configuration is via YAML. Extensions to `LeftAndMain` are applied via `config.yml`.

Usage
-----

[](#usage)

### Select2Field

[](#select2field)

The `Select2Field` class is used exactly the same way as a regular old `DropdownField`:

```
use SilverWare\Select2\Forms\Select2Field;

$field = Select2Field::create(
  'MySelect2Field',
  'Select2 Field',
  [
    1 => 'An',
    2 => 'Array',
    3 => 'of',
    4 => 'Options'
  ]
);
```

#### Select2 Configuration

[](#select2-configuration)

You can define any of the Select2 configuration settings by using the `setConfig()` method:

```
$field->setConfig('maximum-input-length', 20);
```

Alternatively, you can set the defaults for all `Select2Field` instances in your app by using YAML config:

```
SilverWare\Select2\Forms\Select2Field:
  default_config:
    maximum-input-length: 20
```

**NOTE:** configuration setting names are defined using HTML attribute style, and not camel case, for example:

```
$field->setConfig('maximum-input-length', 20);  // this will work
$field->setConfig('maximumInputLength', 20);    // this will NOT work
```

### Select2AjaxField

[](#select2ajaxfield)

The `Select2AjaxField` is used to search a `DataList` based on a search term entered by the user. The results are retrieved from the server via Ajax and rendered as dropdown options. This is very handy for cases where the number of available options in a regular dropdown would be prodigious.

The field is created like any other field:

```
use SilverWare\Select2\Forms\Select2AjaxField;

$field = Select2AjaxField::create(
  'MySelect2AjaxField',
  'Select2 Ajax Field'
);
```

But we do not pass an array of options to choose from to the constructor. Instead, we configure the field to search a `DataList` on the server-side. Here are the default settings:

```
$field->setDataClass(SiteTree::class);  // by default, the field searches for SiteTree records

$field->setIDField('ID');       // the name of the field which identifies the record
$field->setTextField('Title');  // the name of the field to use for the option text

$field->setSearchFields([
  'Title'  // an array of fields to search based on the entered term
]);

$field->setSortBy([
  'Title' => 'ASC'  // an array which defines the sort order of the results
]);

$field->setLimit(256);  // the maximum number of records to return
```

As mentioned, these are the default settings, and the field will work out-of-the-box for `SiteTree` searches.

#### Exclusions

[](#exclusions)

You can also optionally define a series of exclusion filters, which use the same format for the `exclude` method of `DataList`:

```
$field->setExclude([
  'Title:ExactMatch' => 'Hide This Title'
]);
```

Any records matching the defined exclusion filters will be excluded from the results.

#### Formatting

[](#formatting)

By default, the field will render a regular series of dropdown options based on the `$ID` and `$Title` of the matching records, however you can apply more advanced formatting for both results and the current selection. For example:

```
$field->setFormatResult('Found: $Title');
$field->setFormatSelection('Selected: $Title');
```

HTML will be rendered as a jQuery object, so be sure to wrap it in an enclosing element such as a ``.

#### Ajax Configuration

[](#ajax-configuration)

Any of the Select2 Ajax settings can be defined using the `setAjaxConfig()` method:

```
$field->setAjaxConfig('cache', false);
$field->setAjaxConfig('delay', 500);
```

Alternatively, you can set the defaults for all `Select2AjaxField` instances in your app by using YAML config:

```
SilverWare\Select2\Forms\Select2AjaxField:
  default_ajax_config:
    cache: false
    delay: 500
```

**NOTE:** configuration setting names are defined using HTML attribute style, and not camel case, for example:

```
$field->setAjaxConfig('data-type', 'json');  // this will work
$field->setAjaxConfig('dataType', 'json');   // this will NOT work
```

Issues
------

[](#issues)

Please use the [GitHub issue tracker](https://github.com/praxisnetau/silverware-select2/issues) for bug reports and feature requests.

Contribution
------------

[](#contribution)

Your contributions are gladly welcomed to help make this project better. Please see [contributing](CONTRIBUTING.md) for more information.

Attribution
-----------

[](#attribution)

- Makes use of [Select2](https://github.com/select2/select2) by [Kevin Brown](https://github.com/kevin-brown), [Igor Vaynberg](https://github.com/ivaynberg) and [others](https://github.com/select2/select2/graphs/contributors).

Maintainers
-----------

[](#maintainers)

[![Colin Tucker](https://avatars3.githubusercontent.com/u/1853705?s=144)](https://github.com/colintucker)[![Praxis Interactive](https://avatars2.githubusercontent.com/u/1782612?s=144)](https://www.praxis.net.au)[Colin Tucker](https://github.com/colintucker)[Praxis Interactive](https://www.praxis.net.au)License
-------

[](#license)

[BSD-3-Clause](LICENSE.md) © Praxis Interactive

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance4

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~34 days

Recently: every ~61 days

Total

9

Last Release

2894d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f5d47a59cd183aa3f599c2b66dfce7c79c249c2eacb749f0ac8c38c4ca273d14?d=identicon)[PraxisNetAu](/maintainers/PraxisNetAu)

---

Top Contributors

[![colintucker](https://avatars.githubusercontent.com/u/1853705?v=4)](https://github.com/colintucker "colintucker (18 commits)")

---

Tags

dropdownfieldselect2silverstripe-4silverwaresilverstripeselect2silverware

### Embed Badge

![Health badge](/badges/silverware-select2/health.svg)

```
[![Health](https://phpackages.com/badges/silverware-select2/health.svg)](https://phpackages.com/packages/silverware-select2)
```

###  Alternatives

[silverstripe/cms

The SilverStripe Content Management System

5163.4M1.3k](/packages/silverstripe-cms)[silverstripe/admin

SilverStripe admin interface

262.6M325](/packages/silverstripe-admin)[silverstripe/silverstripe-omnipay

SilverStripe Omnipay Payment Module

38106.0k15](/packages/silverstripe-silverstripe-omnipay)[silverleague/ideannotator

Generate PHP DocBlock annotations for DataObject and DataExtension databasefields and relation methods

4768.0k43](/packages/silverleague-ideannotator)[silverware/calendar

SilverWare Calendar Module.

1644.2k1](/packages/silverware-calendar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
