Skip to content

Commit

Permalink
Fix Twig template Form Type Autocomplete (sonata-project#5628)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ennio Wolsink authored and OskarStark committed Sep 6, 2019
1 parent 5772753 commit 60a8c43
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ file that was distributed with this source code.
$(document).ajaxSuccess(function(event, xhr, settings) {
if(typeof xhr.responseJSON != 'undefined') {
if ('{{ create_url }}'.indexOf(settings.url) !== -1 && typeof xhr.responseJSON != 'string' && xhr.responseJSON.result == 'ok') {
var form = JSON.parse('{"' + decodeURI(settings.data).replace('+', ' ').replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
var item = new Option(
new DOMParser().parseFromString(xhr.responseJSON.objectName, "text/html").documentElement.textContent,
xhr.responseJSON.objectId,
Expand All @@ -298,7 +297,11 @@ file that was distributed with this source code.
var data = item;
{%- endif -%}
$('#{{ id }}_hidden_inputs_wrap').html('<input type="hidden" name="{{ full_name }}" value="'+xhr.responseJSON.objectId+'" />');
{% if multiple %}
$('#{{ id }}_hidden_inputs_wrap').append('<input type="hidden" name="{{ full_name }}[]" value="'+xhr.responseJSON.objectId+'" />');
{% else %}
$('#{{ id }}_hidden_inputs_wrap').html('<input type="hidden" name="{{ full_name }}" value="'+xhr.responseJSON.objectId+'" />');
{% endif %}
// append to Select2
autocompleteInput.select2('data', data).append(data).trigger('change');
Expand Down

0 comments on commit 60a8c43

Please sign in to comment.