symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony
https://ux.symfony.com/
MIT License
820 stars 298 forks source link

[UX Autocomplete] setting "tom_select_options" overrides some default values set by ux which breaks plugin #2002

Open sabat24 opened 2 months ago

sabat24 commented 2 months ago

Tested on 2.10.

When creating FormType:

  1. Set autocomplete_url to some custom url.
  2. Set some custom plugin you want to add via tom_select_options
$builder->add('field', ChoiceType::class, [
                'choices' => [
                    'Select something' => '',
                ],
                'autocomplete' => true,
                'autocomplete_url' => 'custom_url,
                'tom_select_options' => [
                    'plugins' => ['dropdown_input'],
                ]
            ]);
  1. On site open select to choose something and you will get an error in console from ux-autocomplete controller

Uncaught TypeError: this.getUrl is not a function

The error is caused because of that ux-autocomplete controller adds virtual_scroll as a plugin by default when url option is set. However providing plugins option directly overrides it. Knowing that fact I can set of course it manually

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

It would be nice if some required default options were merged instead of replacing them. Or at least there may be some information in doc what kind of options should be set to not override those created by ux-autocomplete controller.

smnandre commented 1 month ago

This seems to be the same as: #1128

Do you think you could open a PR to fix this bug and merge correctly ?

sabat24 commented 1 month ago

This seems to be the same as: https://github.com/symfony/ux/issues/1128

Yes. It's a duplicate.

Do you think you could open a PR to fix this bug and merge correctly ?

Probably yes. However, I am struggling with a higher priority issue related to Autocomplete and LiveComponent, so I will start to work on this not earlier then 3 weeks.