ux icon indicating copy to clipboard operation
ux copied to clipboard

When specfying `tom_select_options` on `AsEntityAutocompleteField`: errors `Uncaught TypeError: this.getUrl is not a function`

Open bendavies opened this issue 2 years ago • 8 comments

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

bendavies avatar Sep 21 '23 10:09 bendavies

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

bendavies avatar Sep 21 '23 10:09 bendavies

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()?

weaverryan avatar Sep 21 '23 12:09 weaverryan

get URL comes from the virtual scroll plugin. Which isn't loaded.

bendavies avatar Sep 21 '23 12:09 bendavies

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

bendavies avatar Sep 21 '23 12:09 bendavies

this can be worked around by specifying all the options you need

'tom_select_options' => [
    'plugins' => ['dropdown_input', 'virtual_scroll', 'clear_button'],
],

bendavies avatar Nov 24 '23 14:11 bendavies

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar May 25 '24 14:05 carsonbot

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

carsonbot avatar Jun 08 '24 14:06 carsonbot

yes

bendavies avatar Jun 10 '24 13:06 bendavies

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Dec 11 '24 12:12 carsonbot

no

bendavies avatar Dec 11 '24 13:12 bendavies

Would you like to try bringing a fix here ?

smnandre avatar Dec 11 '24 22:12 smnandre

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

carsonbot avatar Jun 12 '25 12:06 carsonbot

no

bendavies avatar Jun 12 '25 13:06 bendavies

PR opened #2841

Kocal avatar Jun 13 '25 15:06 Kocal