Skip to content

Commit

Permalink
Merge 954e050 into ed37ba4
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Nov 18, 2019
2 parents ed37ba4 + 954e050 commit 109e825
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions assets/js/Autocomplete.js
Expand Up @@ -22,6 +22,7 @@ export default class Autocomplete {
const defaults = {
ajaxRoute: '',
minChars: 3,
text: '',
};

this.settings = {...defaults, ...options};
Expand All @@ -40,6 +41,10 @@ export default class Autocomplete {
},
});

if (this.settings.text) {
element.value = this.settings.text;
}

element.addEventListener('input', async function () {
autocomplete.list = await self.fetchResult(element.value);

Expand All @@ -56,6 +61,7 @@ export default class Autocomplete {
const shadowInput = document.createElement('input');
shadowInput.setAttribute("type", "hidden");
shadowInput.setAttribute("name", element.name);
shadowInput.value = element.value;

element.parentNode.insertBefore(shadowInput, element.nextSibling);
element.setAttribute("name", element.name + '_autocomplete');
Expand Down
3 changes: 2 additions & 1 deletion src/Bridge/Symfony/Resources/views/Form/widgets.html.twig
Expand Up @@ -115,8 +115,9 @@
{% set attr = attr|merge({
'data-autocomplete': {
'ajaxRoute': path(route_name),
'text': text|default(''),
}|json_encode,
'placeholder': text|default(empty_value|trans({}, translation_domain))
'placeholder': empty_value|trans({}, translation_domain)
}) %}
{{ block('form_widget') }}
{% endblock %}

0 comments on commit 109e825

Please sign in to comment.