contao-components/choices
Contao Components Choices adds the Choices.js library integration for Contao CMS, enhancing select boxes and input fields with searchable, taggable, and multi-select UI features. Ideal for modern form UX with minimal setup.
contao-components/choices package provides a PHP wrapper for Choices.js, a lightweight, headless, and accessible autocomplete library. It is well-suited for Laravel applications requiring searchable dropdowns, select boxes, or tag inputs with minimal JavaScript overhead.<select> and <datalist> support, Choices.js offers richer UX (e.g., debounced search, custom templates). For simpler needs, native HTML may suffice, but this package justifies its use for complex interactions.Choices::make('select-id')
->placeholder('Search...')
->debounce(300)
->render();
This generates the necessary JavaScript/CSS and ties into Laravel’s asset compilation.Popper.js for positioning). Laravel Mix/Vite can bundle these efficiently.choices.js and choices.css are properly included in the build. Vite users should alias the package in vite.config.js.<select> elements for UX improvements, or building a custom autocomplete system?resources/js/app.js:
import 'choices.js/public/assets/styles/choices.min.css';
import Choices from 'choices.js';
{!! Choices::make('user-roles')
->options($roles)
->placeholder('Select a role...')
->render() !!}
/api/search-roles?q={query}).Role::where('name', 'like', "%{$query}%")->get()).<select> with x-model might suffice.<select> elements to identify candidates for Choices.js (e.g., searchable dropdowns).php artisan tinker to generate Choices.js config).<select>).window.Choices to initialize after page load.wire:ignore or via Alpine.js.composer require contao-components/choices.resources/js/app.js and include in Laravel Mix/Vite.<select> with the PHP wrapper in a Blade template.validate).test('selects a role via Choices.js')).contao-components/choices for updates (though it’s a thin wrapper, Choices.js itself may change).choices.js version in package.json and rebuild assets.package.json to avoid breaking changes.npm audit or yarn audit to track vulnerabilities.README.md snippet for future developers.choices.js or Popper.js (check asset compilation).Choices.destroy('select-id') to clean up instances before reinitializing.<select> remains functional if Choices.js fails to load.take(50)).choices-virtual-scroll (may require custom integration).Cache::remember).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Choices.js JS bundle fails to load | Broken UX, non-functional selects | Fallback to native <select> with novalidate and user notification. |
| API endpoint for autocomplete fails | Stale or empty dropdowns | Implement client-side caching or retry logic. |
| CSS conflicts |
How can I help you explore Laravel packages today?