PHPackages                             dakujem/selectoo - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dakujem/selectoo

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dakujem/selectoo
================

SelectBox &amp; MultiSelectBox hybrid input with lazy &amp; asynchronous options loading capabilities to be used with Select2, Selectize, Chosen and similar UI libraries.

2.2(1y ago)126.4k↓29.4%4UnlicensePHPPHP &gt;=8.1

Since Jan 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dakujem/selectoo)[ Packagist](https://packagist.org/packages/dakujem/selectoo)[ RSS](/packages/dakujem-selectoo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (14)Used By (0)

Selectoo
========

[](#selectoo)

![PHP from Packagist](https://camo.githubusercontent.com/6a97e6663549e7fb7a0500b9fe5d1716b6274ae3b8099a2f90836261dd622bb2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f64616b756a656d2f73656c6563746f6f2e737667)

SelectBox &amp; MultiSelectBox hybrid input with lazy &amp; asynchronous options loading capabilities to be used with Select2, Selectize, Chosen and similar UI libraries.

The aim of Selectoo is to provide a flexible tool for creating reusable select inputs.

Features
--------

[](#features)

- can work in single-choice or multi-choice modes
    - single-choice mode is roughly equal to `SelectBox`
    - multi-choice mode is roughly equal to `MultiSelectBox`
- on-demand (lazy) loading of options using a callback
    - options can be loaded asynchronously using AJAX
    - options are only loaded when really needed
- can be skinned with UI libraries or custom scripts (see below)
- dependent / cascading inputs

Usage / Use cases
-----------------

[](#usage--use-cases)

**Reusable** inputs with specific setup:

- select2-skinned (or other library) input with special configuration options and other application logic
- autocomplete with ajax
- tagging
- custom ui script for altering the DOM upon selection
- cascading / dependent inputs

> See included examples for more information.

Configuring Selectoo input
--------------------------

[](#configuring-selectoo-input)

Create a (multi)select box with fixed options

```
$items = ['a', 'b', 'c', 'd',];
$input = new Selectoo($label, $items, $multiselect);
```

or a (multi)select box with options loaded on demand (lazy loading).

```
$input = new Selectoo($label, [$repository, 'fetchAll'], $multiselect);
```

An engine can optionally be attached

```
$input->setEngine(new Select2Engine);
```

and configured.

```
$input->getEngine()

	->placeholder('Select a user', true)
	->width('width: 100%', true)
	->closeOnSelect(false, true)

;
```

The `Select2Engine` is configured using magic options (or `setOption` method). The names of the magic methods (or option names) represent the **Select2 configuration options**.

Lazy options loading &amp; AJAX
-------------------------------

[](#lazy-options-loading--ajax)

Lazy loading is used when the Selectoo instance is given "item callback" callable instead of an array of items. The callable is supposed to return a list of items.

The item callback also works as a validator for values. It receives raw value as the first argument (and the input instance as the second). The callback should return the array of possible values (these are the items) in form exactly the same as the items set to `SelectBox` or `MultiSelectBox` inputs. The raw value is then compared to the returned items and filtered. This approach ensures the validity of the data.

It is important to set this callback in case you work with remote item loading (ajax/api loading of options).

See the [example ajax presenter](examples/ajax/ExamplePresenter.php), complete with input factory and user repository examples.

Ajax configuration can be very simple:

```
(new Select2Engine())
	->ajax('{url: "' . $link . '", dataType: "json" }')
;
```

Supported and intended UI libraries
-----------------------------------

[](#supported-and-intended-ui-libraries)

Selectoo uses "script engines" to generate JavaScript UI scripts along with HTML input element. Any script engine can be attached to the `Selectoo` instance by calling `$selectoo->setEngine($engine)`.

- [select2/select2](https://github.com/select2/select2)
    - use the `Select2Engine` instances
- selectize/selectize.js
    - to be implemented
- harvesthq/chosen
    - to be implemented

Custom engines can easily be created implementing the `ScriptEngineInterface` interface.

Factories
---------

[](#factories)

For best reusability I strongly encourage using factories for inputs with more logic, typically these involve fetching data from storage or external resources along with JS/UI configuration, handling events and value validation.

See simple examples:

- [general selectoo factory](examples/factories/Select2SelectooFactory.php)
- [example user select factory](examples/factories/UserSelectooFactory.php)
- [example AJAX API loaded input](examples/ajax/UserAjaxSelectooFactory.php)

Script management
-----------------

[](#script-management)

The scripts generated by engines can be post-processed and/or collected by a management routine. This approach can be used to gather and place the scripts at the end of the page and to solve problems when writing scripts inside the page and loading jQuery at the end of the HTML file.

See [script-management example](examples/script-management/Select2SelectooWithCollectorFactory.php) for more information.

Dependent selections / cascading inputs
---------------------------------------

[](#dependent-selections--cascading-inputs)

Example is being prepared.

What is needed, in general:

- UI script that manages on change events
- Select2 configuration that sends the value of master inputs in the URL of the AJAX request
- repository filtering based upon the values
- API endpoint that receives the master values and makes repository request, using values from the URL
- "item callback" that also makes repository request, using values from `Form`

> Note that when the item callback is called the values from the `Form` object can be used to check for master values

> By "master values" above I mean the values of the inputs the Selectoo instance depends on

By following these steps, dependent Selectoo inputs can be created and values validated.

Examples
--------

[](#examples)

Please see the examples included in the repository to get a better understanding of when Selectoo comes handy.

Notable differences compared to Nette SelectBox &amp; MultiSelectBox
--------------------------------------------------------------------

[](#notable-differences-compared-to-nette-selectbox--multiselectbox)

- disabling a Selectoo input does not modify/reset its value, so it can be re-enabled without the loss of the information
- disabled input is handled differently - raw value is always loaded even when input (or items) is disabled. The disabled values are filtered when calling `getValue` method.

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

[](#requirements)

SelectooPHPNette formsversion `2.0``7.1+``3.*`version `1.0``7.0+``2.4.*`You should also install **Select2** version `4` to use the `Select2Engine`, see [Select2 documentation](https://select2.org/).

You may install any other select input "skin" and implement your own engine for it within minutes.

Selectoo can also be used without such a "skin".

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance41

Moderate activity, may be stable

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 97.8% 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 ~213 days

Recently: every ~133 days

Total

13

Last Release

494d ago

Major Versions

v0.3.1 → 1.02018-01-17

1.0 → 2.02020-03-02

v1.x-dev → 2.12023-10-27

PHP version history (5 changes)0.1PHP ^7.0

2.0PHP ^7.1

1.0.2PHP &gt;=7.0

2.1PHP &gt;=7.1

2.2PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/0bd7fa945013e9c0dcd65693575276bf5fcb9b9de13e1123e9f2c4a0a4c0fb6b?d=identicon)[dakujem](/maintainers/dakujem)

---

Top Contributors

[![dakujem](https://avatars.githubusercontent.com/u/443067?v=4)](https://github.com/dakujem "dakujem (45 commits)")[![mdsystem](https://avatars.githubusercontent.com/u/1016800?v=4)](https://github.com/mdsystem "mdsystem (1 commits)")

---

Tags

cascading-inputscomponentjavascript-wrappernetteselectboxautocompletejavascriptnetteForms

### Embed Badge

![Health badge](/badges/dakujem-selectoo/health.svg)

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

###  Alternatives

[contributte/forms-multiplier

Multiplier for nette forms

281.4M3](/packages/contributte-forms-multiplier)[kdyby/forms-replicator

Nette forms container replicator aka addDynamic

32997.7k6](/packages/kdyby-forms-replicator)[contributte/forms-wizard

Wizard component for nette/forms

15783.7k](/packages/contributte-forms-wizard)[webchemistry/forms-multiplier

Multiplier for nette forms

2860.9k](/packages/webchemistry-forms-multiplier)[vojtech-dobes/nette-forms-gpspicker

Google Maps based picker of coordinates for Nette Framework.

2456.6k](/packages/vojtech-dobes-nette-forms-gpspicker)[czubehead/bootstrap-4-forms

Nette extension for Bootstrap 4 forms

1019.5k1](/packages/czubehead-bootstrap-4-forms)

PHPackages © 2026

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