Skip to content

Commit

Permalink
bug #447 [Autocomplete] Fix extending Tom Select when using custom Aj…
Browse files Browse the repository at this point in the history
…ax class (ralfkuehnel)

This PR was merged into the 2.x branch.

Discussion
----------

[Autocomplete] Fix extending Tom Select when using custom Ajax class

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Tickets       | Fix #...
| License       | MIT

I have tried to follow the [documentation](https://symfony.com/bundles/ux-autocomplete/current/index.html#extending-tom-select) to extend Tom Select using a custom Stimulus controller. It worked when updating the field configuration but did not when using a custom Ajax class. In this case the core Autocomplete Stimulus controller was missing in the rendered data-controller-Tag. Changing the autocomplete form theme to use the attributes from the autocomplete field seems to fix this!

Commits
-------

3abb968 [Autocomplete] Fix extending Tom Select when using custom ajax class
  • Loading branch information
weaverryan committed Sep 16, 2022
2 parents 804ed74 + 3abb968 commit 5a13c71
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{# EasyAdminAutocomplete form type #}
{% block ux_entity_autocomplete_widget %}
{{ form_widget(form.autocomplete, { attr: attr|merge({ required: required }) }) }}
{{ form_widget(form.autocomplete, { attr: form.autocomplete.vars.attr|merge({ required: required }) }) }}
{% endblock ux_entity_autocomplete_widget %}

{% block ux_entity_autocomplete_label %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function configureOptions(OptionsResolver $resolver)
return true;
},
'placeholder' => 'What should we eat?',
'attr' => [
'data-controller' => 'custom-autocomplete',
],
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testFieldsRenderWithStimulusController()
$this->browser()
->throwExceptions()
->get('/test-form')
->assertElementAttributeContains('#product_category_autocomplete', 'data-controller', 'symfony--ux-autocomplete--autocomplete')
->assertElementAttributeContains('#product_category_autocomplete', 'data-controller', 'custom-autocomplete symfony--ux-autocomplete--autocomplete')
->assertElementAttributeContains('#product_category_autocomplete', 'data-symfony--ux-autocomplete--autocomplete-url-value', '/test/autocomplete/category_autocomplete_type')

->assertElementAttributeContains('#product_portionSize', 'data-controller', 'symfony--ux-autocomplete--autocomplete')
Expand Down

0 comments on commit 5a13c71

Please sign in to comment.