Skip to content

[Autocomplete] Impossible to define custom options in a EntityAutocompleteType class #420

Open
@garak

Description

@garak

Description

I followed the documentation of UX-Autocomplete and I created my custom form type. Problem is that I expect to be able to use some custom options. I can't. It looks like the AutocompleteEntityTypeSubscriber is just assuming you don't use any custom options and it's passing all the options to an "autocomplete" field. See https://github.com/symfony/ux-autocomplete/blob/2.x/src/Form/AutocompleteEntityTypeSubscriber.php#L44

How to reproduce

Just follow the instructions provided in documentation https://symfony.com/bundles/ux-autocomplete/current/index.html#usage-in-a-form-with-ajax and add a custom option, like "allowed_states" in the example provided in https://symfony.com/doc/current/form/create_custom_field_type.html#adding-configuration-options-for-the-form-type.
As soon as you try to use the form with your custom form type (no matter if you use your custom option or not), you get the following exception:

An error has occurred resolving the options of the form "Symfony\Bridge\Doctrine\Form\Type\EntityType": The option "allowed_states" does not exist. Defined options are: "action", "allow_extra_fields", "allow_file_upload", "allow_options_create", "attr", "attr_translation_parameters", "auto_initialize", "autocomplete", "autocomplete_url", "block_name", "block_prefix", "by_reference", "choice_attr", "choice_filter", "choice_label", "choice_loader", "choice_name", "choice_translation_domain", "choice_translation_parameters", "choice_value", "choices", "class", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "em", "empty_data", "error_bubbling", "error_mapping", "expanded", "extra_fields_message", "form_attr", "getter", "group_by", "help", "help_attr", "help_html", "help_translation_parameters", "id_reader", "inherit_data", "invalid_message", "invalid_message_parameters", "is_empty_callback", "label", "label_attr", "label_format", "label_html", "label_translation_parameters", "mapped", "method", "multiple", "no_more_results_text", "no_results_found_text", "options_as_html", "placeholder", "post_max_size_message", "preferred_choices", "priority", "property_path", "query_builder", "required", "row_attr", "setter", "tom_select_options", "translation_domain", "trim", "upload_max_size_message", "validation_groups".

Possible Solution

I don't know if the current implementation could be fixed.
If not, the documentation should be updated, adding a big warning that the developer must not define any custom option in their custom form type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugBug FixdocsImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions