Skip to content

Commit

Permalink
[MINOR] Allow empty value for autocomplete form (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Sep 8, 2019
2 parents 5efaf10 + 897a5d1 commit e9286fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Bridge/Symfony/Resources/views/Form/widgets.html.twig
Expand Up @@ -113,7 +113,10 @@

{% block core23_autocomplete_widget %}
{% set attr = attr|merge({
'data-select2-autocomplete': { 'ajaxRoute': path(route_name), 'text': text }|json_encode,
'data-select2-autocomplete': {
'ajaxRoute': path(route_name),
'text': text|default(empty_value|trans({}, translation_domain))
}|json_encode,
}) %}
{{ block('form_widget') }}
{% endblock %}
8 changes: 5 additions & 3 deletions src/Type/AutocompleteType.php
Expand Up @@ -24,7 +24,8 @@ public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefaults([
'property' => null,
'property' => null,
'empty_value' => '',
])
->setRequired('route_name')
;
Expand All @@ -43,8 +44,9 @@ public function buildView(FormView $view, FormInterface $form, array $options):
}
}

$view->vars['text'] = $text;
$view->vars['route_name'] = $options['route_name'];
$view->vars['text'] = $text;
$view->vars['route_name'] = $options['route_name'];
$view->vars['empty_value'] = $options['empty_value'];
}

public function getBlockPrefix()
Expand Down

0 comments on commit e9286fd

Please sign in to comment.