Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The option "extra_options" does not exist. #1541

Closed
adalbertus opened this issue Feb 23, 2024 · 4 comments
Closed

The option "extra_options" does not exist. #1541

adalbertus opened this issue Feb 23, 2024 · 4 comments

Comments

@adalbertus
Copy link

Hi
I'm now upgrading my Symfony 6.3 application to 6.4 and I've also updated symfony/ux-autocomplete to the 2.15.0 version.

Now each time I'm trying to use my autocomplete field I'm getting error:
An error has occurred resolving the options of the form "App\Form\Autocomplete\MemberSingleAutocompleteField": The option "extra_options" does not exist. Defined options are: "action", "allow_extra_fields", ....
I've noticed that this extra_options was introduced in #1322.

Should I stick to 2.14 version in order to use it with 6.4 Symfony?

@smnandre
Copy link
Member

The extra_options exists in 2.15.0, but it is available for form types extending from:

        return [
            ChoiceType::class,
            TextType::class,
        ];

What does your MemberSingleAutocompleteField descend from ?

@thorstenlbk
Copy link

thorstenlbk commented Feb 25, 2024

I am getting the error, too.

An error has occurred resolving the options of the form "App\Form\KundendatenAutocompleteField": The option "extra_options" does not exist. Defined options are: "action",

The relevant parts of KundendatenAutocompleteField:

use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
...
class KundendatenAutocompleteField extends ChoiceType
...

Using Symfony\Component\Form\AbstractType or Symfony\Component\Form\Extension\Core\Type\TextType results in the same error.

@bdujon
Copy link
Contributor

bdujon commented Feb 26, 2024

For autocomplete since 2.13 you need
public function getParent(): string { return BaseEntityAutocompleteType::class; }

instead of
public function getParent(): string { return ParentEntityAutocompleteType::class; }

https://symfony.com/bundles/ux-autocomplete/current/index.html#usage-in-a-form-with-ajax
at least that was my issue

@adalbertus
Copy link
Author

@bdujon - brilliant! 😄 It is working now. Thank you!

I wonder that maybe it would be worth to add it as a comment in symfony console make:autocomplete-field?
Autogenerated class uses ParentEntityAutocompleteType::class; which is fine when you are not using Ajax but is not otherwise. Error message was missleading here (at least for me).

For example:

Customize your new field class, then add it to a form:
 
     $builder
         // ...
         ->add('user', Foo::class)
     ;

Add somethig like: Change getParent() acordingly if using with Ajax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants