When specfying `tom_select_options` on `AsEntityAutocompleteField`: errors `Uncaught TypeError: this.getUrl is not a function`
Hi,
If you define an AsEntityAutocompleteField as per the docs, but add some tom_select_options,
FoodAutocompleteField.php
<?php
// src/Form/FoodAutocompleteField.php
// ...
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField;
use Symfony\UX\Autocomplete\Form\ParentEntityAutocompleteType;
#[AsEntityAutocompleteField]
class FoodAutocompleteField extends AbstractType
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'class' => Food::class,
'placeholder' => 'What should we eat?',
'tom_select_options' => [
'plugins' => ['dropdown_input'],
],
}
public function getParent(): string
{
return ParentEntityAutocompleteType::class;
}
}
you will receive a javascript error when the ajax calls is made to load items:
Uncaught TypeError: this.getUrl is not a function
which comes from here: https://github.com/symfony/ux-autocomplete/blob/6a1851b8ed5e51c0a285728b0e51522e62ae6fdd/assets/dist/controller.js#L286
This comment is suspicious: https://github.com/symfony/ux-autocomplete/blob/2.x/assets/src/controller.ts#L178-L180
Thanks, Ben
This appears to be because the plugins provided here override the default ones (virtual_scroll) during the config merge:
https://github.com/symfony/ux-autocomplete/blob/6a1851b8ed5e51c0a285728b0e51522e62ae6fdd/assets/src/controller.ts#L172
We probably need a way to ADD plugins instead of replacing.
But first, why exactly does clearing all of the plugins create this error? Why is “this” suddenly missing the getUrl()?
get URL comes from the virtual scroll plugin. Which isn't loaded.
Adding plugins seems like a good idea, but it looks like to me that virtual scroll plugin should always be loaded if urlValue is defined. That would be the easiest fix for now
this can be worked around by specifying all the options you need
'tom_select_options' => [
'plugins' => ['dropdown_input', 'virtual_scroll', 'clear_button'],
],
Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?
Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3
yes
Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?
no
Would you like to try bringing a fix here ?
Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?
no
PR opened #2841