symfony/ux-autocomplete
JavaScript-powered autocomplete for Symfony forms. Enhances select and entity fields with search-as-you-type suggestions, async loading, and a smooth UX. Part of Symfony UX; docs and issues live in the main symfony/ux repository.
hash_equals() to compare the extra_options checksum to prevent timing attacksParentEntityAutocompleteType in favor of BaseEntityAutocompleteTypeExtraLazyChoiceLoader in favor of Symfony\Component\Form\ChoiceList\Loader\LazyChoiceLoader from Symfony Form >=7.2$security to AutocompleteResultsExecutor::__construct()EntityAutocompleterInterface::getAttributes() and EntityAutocompleterInterface::getGroupBy()ParentEntityAutocompleteType in favor of BaseEntityAutocompleteTypeExtraLazyChoiceLoader in favor of Symfony\Component\Form\ChoiceList\Loader\LazyChoiceLoader from Symfony Form >=7.2$security to AutocompleteResultsExecutor::__construct()EntityAutocompleterInterface::getAttributes() and EntityAutocompleterInterface::getGroupBy()The autocomplete now watches for update to any option elements inside of
it change, including the empty / placeholder element. Additionally, if the
select or input element's disabled attribute changes, the autocomplete
instance will update accordingly. This makes Autocomplete work correctly inside
of a LiveComponent. This functionality does not work for multiple selects.
Added support for using OptionGroups.
Add assets/src to .gitattributes to exclude them from the installation
Fix minCharacters option default value handling when using a falsy value like 0.
Fix TypeScript types
Add a new route parameter to AsEntityAutocompleteField, which allows to choose another route for Ajax calls.
Fix minCharacters option default value handling when using a falsy value like 0.
Fix TypeScript types
Add a way to detect if a field is an "autocomplete" field in form themes - #608
routes.php changed and you should update your
route import accordingly:# config/routes/ux_autocomplete.yaml
ux_autocomplete:
- resource: '[@AutocompleteBundle](https://github.com/AutocompleteBundle)/Resources/routes.php'
+ resource: '[@AutocompleteBundle](https://github.com/AutocompleteBundle)/config/routes.php'
prefix: '/autocomplete'
tom-select version 2.2.2 and made this the minimum-supported
version.preload TomSelect option.max_results was not passed as a Stimulus value (#538).Automatic pagination support added: if the query would return more results than your limit, when the user scrolls to the bottom of the options, it will make a second Ajax call to load more.
Added max_results option to limit the number of results returned by the
Ajax endpoint - #478.
Support added for setting the required minimum search query length (defaults to 3) (#492)
Fix support for more complex ids, like UUIDs - #494.
Fixed bug where sometimes an error could occur in the Ajax call related to the label - #520.
ESCAPE '\' clause introduced in 2.36; a backslash-free LIKE escape character is now used.ESCAPE '\' clause introduced in 2.36; a backslash-free LIKE escape character is now used.Escape LIKE wildcards (% and _) in the autocomplete search query so user
input can no longer alter the matching behavior of the generated SQL query.
Fix XSS vulnerability where data returned from AJAX endpoints was rendered without HTML escaping.
Values from the text field of AJAX responses are now escaped by default.
Possible BC break: if your endpoint legitimately returns HTML in the text field (e.g., for rich content), opt in via the options_as_html option:
#[AsEntityAutocompleteField]
class IngredientAutocompleteType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Ingredient::class,
+ 'options_as_html' => true,
]);
}
}
reset_on_focus option to clear and reload options when the autocomplete field regains focusclear_button or remove_button can now be removed when setting their value to false in the tom_select_options.plugins option, for example:<?php
#[AsEntityAutocompleteField]
class IngredientAutocompleteType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => Ingredient::class,
'tom_select_options' => [
'plugins' => [
'clear_button' => false, // Disable the clear button
'remove_button' => false, // Disable the remove button
],
],
]);
}
public function getParent(): string
{
return BaseEntityAutocompleteType::class;
}
}
querySelector dynamic selector with CSS.escape() #2663ExtraLazyChoiceLoader in favor of Symfony\Component\Form\ChoiceList\Loader\LazyChoiceLoaderEntityAutocompleterInterface::getAttributes() method to define additional attributes for autocomplete results #2541labelField TomSelect option into account #2382option_create option from TomSelect with remote data setup #2279option_create option from TomSelect #2108choice_value option in entity autocomplete fields #1723select or option
elements were modified to hopefully, more reliably, reset the autocomplete
instance. This is particularly important with LiveComponents.render.loading_more Tom Select Virtual Scroll option (loading_more_text)tom-select/dist/css/tom-select.bootstrap4.css to autoimport - this
will cause this to appear in your controllers.json file by default, but disabled
see.extra_options key in an array passed as a 3rd argument of the ->add() method.
It will be used during the Ajax call to fetch results.type: module"type: moduleHow can I help you explore Laravel packages today?