Skip to content

Commit 5a13c71

Browse files
committed
bug #447 [Autocomplete] Fix extending Tom Select when using custom Ajax 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
2 parents 804ed74 + 3abb968 commit 5a13c71

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/Autocomplete/src/Resources/views/autocomplete_form_theme.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{# EasyAdminAutocomplete form type #}
22
{% block ux_entity_autocomplete_widget %}
3-
{{ form_widget(form.autocomplete, { attr: attr|merge({ required: required }) }) }}
3+
{{ form_widget(form.autocomplete, { attr: form.autocomplete.vars.attr|merge({ required: required }) }) }}
44
{% endblock ux_entity_autocomplete_widget %}
55

66
{% block ux_entity_autocomplete_label %}

src/Autocomplete/tests/Fixtures/Form/CategoryAutocompleteType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function configureOptions(OptionsResolver $resolver)
3838
return true;
3939
},
4040
'placeholder' => 'What should we eat?',
41+
'attr' => [
42+
'data-controller' => 'custom-autocomplete',
43+
],
4144
]);
4245
}
4346

src/Autocomplete/tests/Functional/AutocompleteFormRenderingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testFieldsRenderWithStimulusController()
2929
$this->browser()
3030
->throwExceptions()
3131
->get('/test-form')
32-
->assertElementAttributeContains('#product_category_autocomplete', 'data-controller', 'symfony--ux-autocomplete--autocomplete')
32+
->assertElementAttributeContains('#product_category_autocomplete', 'data-controller', 'custom-autocomplete symfony--ux-autocomplete--autocomplete')
3333
->assertElementAttributeContains('#product_category_autocomplete', 'data-symfony--ux-autocomplete--autocomplete-url-value', '/test/autocomplete/category_autocomplete_type')
3434

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

0 commit comments

Comments
 (0)