Browse Source

Fix JS loading in autocomplete form type (#4610)

Trigger the select2-JavaScript code at onload event
Julien Chichignoud 7 years ago
parent
commit
b2b39d5cd2

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

@@ -37,7 +37,7 @@ file that was distributed with this source code.
     </div>
     </div>
 
 
     <script>
     <script>
-        (function ($) {
+        jQuery(function ($) {
             // Select2 v3 does not used same input as v4.
             // Select2 v3 does not used same input as v4.
             // NEXT_MAJOR: Remove this BC layer while upgrading to v4.
             // NEXT_MAJOR: Remove this BC layer while upgrading to v4.
             var usedInputRef = window.Select2 ? '#{{ id }}_autocomplete_input' : '#{{ id }}_autocomplete_input_v4';
             var usedInputRef = window.Select2 ? '#{{ id }}_autocomplete_input' : '#{{ id }}_autocomplete_input_v4';
@@ -237,6 +237,6 @@ file that was distributed with this source code.
                 $(usedInputRef).remove();
                 $(usedInputRef).remove();
                 return true;
                 return true;
             });
             });
-        })(jQuery);
+        });
     </script>
     </script>
 {% endspaceless %}
 {% endspaceless %}