PHPackages                             heimrichhannot/contao-choices-bundle - 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. heimrichhannot/contao-choices-bundle

ActiveContao-bundle[Utility &amp; Helpers](/categories/utility)

heimrichhannot/contao-choices-bundle
====================================

This bundle offers support for choices.js for the Contao CMS.

1.5.4(2y ago)01.5k↓70.8%1LGPL-3.0-or-laterPHPPHP ^7.4 || ^8.0

Since Apr 3Pushed 2y ago4 watchersCompare

[ Source](https://github.com/heimrichhannot/contao-choices-bundle)[ Packagist](https://packagist.org/packages/heimrichhannot/contao-choices-bundle)[ RSS](/packages/heimrichhannot-contao-choices-bundle/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (7)Versions (36)Used By (0)

Contao Choices Bundle
=====================

[](#contao-choices-bundle)

This bundle offers support for the JavaScript library [Choices.js](https://github.com/jshjohnson/Choices) for the Contao CMS.

Features
--------

[](#features)

- activate choices support on page level (with inheritance and override option)
- customize options from dca or dynamically from event
- [Encore Bundle](https://github.com/heimrichhannot/contao-encore-bundle) support
- [Filter Bundle](https://github.com/heimrichhannot/contao-filter-bundle) support

Setup
-----

[](#setup)

1. Install via composer: `composer require heimrichhannot/contao-choices-bundle`.
2. Update Database
3. Encore Bundle: Prepare and generate encore entries

Usage
-----

[](#usage)

Active or deactivate choices support on page level (Layout section). You can activate/deactivate it separately for select and text boxes. You can overwrite settings from a parent page.

It is possible to active and deactivate choices support for single field as well.

Using DCA configuration:

```
['field']['eval']['choicesOptions'] = [
    'enable' => true|false
];
```

Using CustomizeChoicesOptionsEventListener

```
public function onHuhChoicesCustomizeChoicesOptions(CustomizeChoicesOptionsEvent $event)
{
    $event->enableChoices();
    $event->disableChoices();
}
```

> NOTE: Choices are enabled by default if activated on page level.

### Configuration

[](#configuration)

Each field can be customized via DCA:

```
['field']['eval']['choicesOptions'] = [];
```

All options from Choices.js can be found at

> NOTE: the only option not from choices.js is `'enable' => true|false`

### Filter Bundle

[](#filter-bundle)

Choices.js support it automatically added to choice type form fields. It can be disabled in the type configuration. For other config types it can be activated in the configuration.

Developers
----------

[](#developers)

### PHP Events

[](#php-events)

To customize options passed to the choices.js library, you can use the `CustomizeChoicesOptionsEvent`. Register an event listener to `huh.choices.customize_choices_options`. This work for 'normal' widgets and filter bundle fields. In your event listener you check, if the event comes from an filter bundle field by calling `CustomizeChoicesOptionsEvent::isFilterField(): bool`. In this case, the complete (but cloned) `AdjustFilterOptionsEvent` is passed to the event and the fieldAttributes array is empty. If you don't use filter bundle, you can ignore the filter bundle part.

```
  HeimrichHannot\CustomBundle\EventListener\CustomizeChoicesOptionsListener:
    tags:
      - { name: kernel.event_listener, event: huh.choices.customize_choices_options }
```

```
use HeimrichHannot\ChoicesBundle\Event\CustomizeChoicesOptionsEvent;

class CustomizeChoicesOptionsListener
{
    public function __invoke(CustomizeChoicesOptionsEvent $event)
    {
        if ($event->isFilterField()) {
            $this->addFilterChoicesOptions($event);
        } else {
            $this->addFieldChoicesOptions($event);
        }
    }
}
```

### JavaScript Events

[](#javascript-events)

Following events can be used to further customize the choices instances:

Event nameDataDescriptionhundhChoicesOptionsoptionsCustomize options before instantiating the choice object.hundhChoicesNewInstanceinstanceIs dispatched right after the choices instance is create.Example:

```
/**
 * @param { CustomEvent } event
 */
function onHundhChoicesOptions(event) {
    let options = event.detail.options;
    // Customize options
}

/**
 * @param { CustomEvent } event
 */
function onHundhChoicesNewInstance(event) {
    let choicesInstance = event.detail.instance;
    // Work with the choices instance
}

document.addEventListener('hundhChoicesOptions', onHundhChoicesOptions);
document.addEventListener('hundhChoicesNewInstance', onHundhChoicesNewInstance);
```

### Custom usage

[](#custom-usage)

If you use the library in a different way than this bundle provides (e.g. a custom module), use the frontend asset service to dynamically add the frontend assets.

```
use HeimrichHannot\ChoicesBundle\Asset\FrontendAsset;

class MyClass
{
    private FrontendAsset $frontendAsset;

    public function action() {
        $this->frontendAsset->addFrontendAssets();
    }
}
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 96% 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 ~56 days

Recently: every ~130 days

Total

33

Last Release

783d ago

Major Versions

0.4.9 → 1.0.02021-08-05

PHP version history (3 changes)0.1.0PHP ^7.1

1.3.0PHP ^7.1 || ^8.0

1.4.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/28ad3224d8727b622ebd229840eea6b9dbcb83eb0bd609e6ce65b614830ff538?d=identicon)[digitales@heimrich-hannot.de](/maintainers/digitales@heimrich-hannot.de)

---

Top Contributors

[![koertho](https://avatars.githubusercontent.com/u/12064642?v=4)](https://github.com/koertho "koertho (48 commits)")[![AlexejKossmann](https://avatars.githubusercontent.com/u/32612134?v=4)](https://github.com/AlexejKossmann "AlexejKossmann (1 commits)")[![ericges](https://avatars.githubusercontent.com/u/25957923?v=4)](https://github.com/ericges "ericges (1 commits)")

### Embed Badge

![Health badge](/badges/heimrichhannot-contao-choices-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/heimrichhannot-contao-choices-bundle/health.svg)](https://phpackages.com/packages/heimrichhannot-contao-choices-bundle)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[codefog/contao-haste

haste extension for Contao Open Source CMS

42650.8k139](/packages/codefog-contao-haste)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6939.5M343](/packages/drupal-core-recommended)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[codefog/contao-news_categories

News Categories bundle for Contao Open Source CMS

3183.3k6](/packages/codefog-contao-news-categories)

PHPackages © 2026

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