Browse Source

Remove unused field

Hiding is not enough. If you are using AJAX, and your field is required,
you may end up with an empty select tag, with a required attribute that
is never filled with options, because there are currently 2 tags, one
for each version of Select2, and only one of them is filled.
This commit removes the other one instead of just hiding it,
that way it can't interfere with the other.
Fixes #4486, fixes #4261
Grégoire Paris 8 years ago
parent
commit
d5815b6137

+ 1 - 1
Resources/views/Form/Type/sonata_type_model_autocomplete.html.twig

@@ -43,7 +43,7 @@ file that was distributed with this source code.
             var usedInputRef = window.Select2 ? '#{{ id }}_autocomplete_input' : '#{{ id }}_autocomplete_input_v4';
             var usedInputRef = window.Select2 ? '#{{ id }}_autocomplete_input' : '#{{ id }}_autocomplete_input_v4';
             var unusedInputRef = window.Select2 ? '#{{ id }}_autocomplete_input_v4' : '#{{ id }}_autocomplete_input';
             var unusedInputRef = window.Select2 ? '#{{ id }}_autocomplete_input_v4' : '#{{ id }}_autocomplete_input';
 
 
-            $(unusedInputRef).hide();
+            $(unusedInputRef).remove();
             var autocompleteInput = $(usedInputRef);
             var autocompleteInput = $(usedInputRef);
 
 
             var select2Options = {
             var select2Options = {