Skip to content

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

Closed
@bendavies

Description

@bendavies

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions