/symfony-ux-skills:ux-autocompletefrom symfony-ux-skills
Adds searchable selects and Ajax autocomplete to Symfony forms using Tom Select. Supports local filtering, Doctrine entity loading, and custom data sources via AutocompleterInterface.
Ships in symfony-ux-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Turn any ChoiceType, EntityType, EnumType, TextType or plain <select> into a searchable control powered by Tom Select. Options are filtered in the browser, or loaded through Ajax from Doctrine or any other data source.
composer require symfony/ux-autocomplete
Requires StimulusBundle. With Encore: npm install --force, then restart npm run watch.
| Situation | Mode | How |
|---|---|---|
| A few dozen options | Local | 'autocomplete' => true on the field |
| Many Doctrine entities | Ajax, entity | Field class with #[AsEntityAutocompleteField], parent BaseEntityAutocompleteType |
| API, search index, enum, array | Ajax, any source | Field class with #[AsAutocompleteField], parent AutocompleteChoiceType |
| No Symfony Form | Ajax endpoint | AutocompleterInterface service + Stimulus controller |
| Free tags | Create items | TextType with 'autocomplete' => true and create |
Since Symfony UX 3.5+, the package works with any data source: #[AsAutocompleteField], AutocompleteChoiceType, AutocompleterInterface, the ux_autocomplete route and max_options.
$builder
->add('food', EntityType::class, [
'class' => Food::class,
'placeholder' => 'What should we eat?',
'autocomplete' => true,
])
->add('portionSize', ChoiceType::class, [
'choices' => ['small' => 's', 'medium' => 'm', 'large' => 'l'],
'autocomplete' => true,
]);
php bin/console make:autocomplete-field # choose "Entity (Doctrine)"
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType;
#[AsEntityAutocompleteField]
final class FoodAutocompleteField extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Food::class,
'placeholder' => 'What should we eat?',
'searchable_fields' => ['name', 'category.name'], // all fields when null
'security' => 'ROLE_USER', // endpoint is public otherwise
]);
}
public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}
$builder->add('food', FoodAutocompleteField::class);
php bin/console make:autocomplete-field # choose "Choice (any data source)"
use Symfony\UX\Autocomplete\Form\AsAutocompleteField;
use Symfony\UX\Autocomplete\Form\AutocompleteChoiceType;
#[AsAutocompleteField]
final class CountryAutocompleteField extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'choices' => ['France' => 'FR', 'Germany' => 'DE', 'United Kingdom' => 'GB'],
'placeholder' => 'Choose a country',
]);
}
public function getParent(): string
{
return AutocompleteChoiceType::class;
}
}
Any ChoiceType option works; choices are filtered and paginated by the endpoint.
The Ajax endpoint rebuilds the field from its class alone. Options passed to ->add() exist on the first render only:
// WRONG: ignored during the Ajax search
$builder->add('food', FoodAutocompleteField::class, [
'query_builder' => fn (EntityRepository $er) => $er->createQueryBuilder('f')->andWhere('f.id != :id'),
]);
// RIGHT: pass scalar data as extra_options, read it in the field class
$builder->add('food', FoodAutocompleteField::class, [
'extra_options' => ['excluded_foods' => [$currentFood->getId()]],
]);
use Symfony\Component\OptionsResolver\Options;
$resolver->setDefaults([
'class' => Food::class,
'query_builder' => function (Options $options) {
return function (EntityRepository $er) use ($options) {
$qb = $er->createQueryBuilder('o');
$excluded = $options['extra_options']['excluded_foods'] ?? [];
if ([] !== $excluded) {
$qb->andWhere($qb->expr()->notIn('o.id', $excluded));
}
return $qb;
};
},
]);
extra_options only carries scalars, null and arrays of those. They travel in the URL, protected against tampering by a checksum.
| Option | Default | Applies to |
|---|---|---|
autocomplete | false | Any choice or text field |
tom_select_options | [] | Any; Tom Select settings, including plugins |
options_as_html | false | Any; labels are escaped unless enabled |
max_options | null (50 for Ajax) | Options displayed at once |
min_characters | 3 | Ajax fields |
max_results | 10 | Results per page returned by the endpoint |
preload | focus | Ajax fields: focus, true or false |
searchable_fields | null (all) | Entity fields; relations allowed (category.name) |
filter_query | null | Entity fields; full control of the search, replaces searchable_fields and max_results |
security | false | Ajax fields: a role or a callable |
extra_options | [] | Ajax fields |
preferred_choices | Since 3.7: listed first in Ajax results; entities only for entity fields |
Texts (loading_more_text, no_results_found_text, no_more_results_text) are translated in the AutocompleteBundle domain. See references/api.md for the full reference, autocompleters, the JSON format and Stimulus values.
In assets/controllers.json, switch the Tom Select theme:
"autoimport": {
"tom-select/dist/css/tom-select.default.css": false,
"tom-select/dist/css/tom-select.bootstrap5.css": true
}
Local first, Ajax when the list is large. Local mode works with the field option alone.
Secure every Ajax field that exposes private data. The endpoint is public by default; set security, or move it under a firewall with a custom route.
Configure in the class, vary with extra_options.
Keep options_as_html off unless labels are trusted HTML. Labels are escaped to prevent XSS.
query_builder / choices / preferred_choices: they were passed to ->add(). Move them into the field class or use extra_options.getParent() returns the wrong type.filter_query with searchable_fields or max_results: incompatible, pick one.stimulusFetch: 'lazy') to catch autocomplete:pre-connect.ux_entity_autocomplete deprecation: use the ux_autocomplete route.TypeTestCase fails on the autocomplete option: register new AutocompleteChoiceTypeExtension() in getTypeExtensions().symfony/ux-autocomplete on Packagist.tom_select_options and JavaScript plugins, see the Tom Select documentation.autocomplete:pre-connect and autocomplete:connect.ComponentWithFormTrait forms.What SKILL.md sets; muted values are Claude Code's defaults
20 skills in this plugin
/live-componentSymfony UX LiveComponent: live search, live filters, dependent selects and form validation as users type. Use for reactive PHP and Twig components, #[AsLiveComponent], LiveProp, LiveAction, data-model, loading states, emit/listen, lazy rendering and LiveResponse downloads./stimulusSymfony UX Stimulus: JavaScript behavior for dropdowns, tabs, modals, clipboard buttons and third-party widgets. Use for StimulusBundle, data-controller, data-action, targets, values, outlets, lazy controllers and Twig stimulus_* helpers./symfony-uxSymfony UX: choose and combine packages for a Symfony frontend. Use when deciding between Stimulus, Turbo, TwigComponent and LiveComponent, or fitting several Symfony UX packages into the same feature. Prefer the dedicated skill for a task that fits one package.npx claudepluginhub smnandre/symfony-ux-skills --plugin symfony-ux-skillsOther plugins' skills for the same job