Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help to use it with sonata admin #163

Open
webetdesign opened this issue Dec 27, 2019 · 2 comments
Open

Need help to use it with sonata admin #163

webetdesign opened this issue Dec 27, 2019 · 2 comments

Comments

@webetdesign
Copy link

I try to use this bundle with sonata admin but i don't a select2 on my fields.

When i include this on my admin layout :
<script src="{{ asset('bundles/tetranzselect2entity/js/select2entity.js') }}"></script>

I got this error :
Uncaught Error: Option 'ajax' is not allowed for Select2 when attached to a element. Someone can help me ?

@alaa-essaies
Copy link

solution is to put cdns on your standard_layout.html.twig :

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
<script src="{{ asset('bundles/tetranzselect2entity/js/select2entity.js') }}"></script>

@alaa-essaies
Copy link

alaa-essaies commented Jun 30, 2020

for jQuery conflict use this code on stadard_layout.html.twig :

        <script src="{{ asset('bundles/select2/dist/js/jquery-3.5.1.min.js') }}"></script>
        <script type="text/javascript">
            var jQueryTemp = jQuery.noConflict(true);
            var jQueryOriginal = jQuery || jQueryTemp;
            if (window.jQuery){
                console.log('Original jQuery: ', jQuery.fn.jquery);
                console.log('Second jQuery: ', jQueryTemp.fn.jquery);
            }
            window.jQuery = window.$ = jQueryTemp;
        </script>
        
        
        <script src="{{ asset('bundles/select2/dist/js/select2.full.js') }}"></script>
        <script src="{{ asset('bundles/tetranzselect2entity/js/select2entity.js') }}"></script>
        
        
        <script src="{{ asset('bundles/select2/dist/js/jquery-2.1.4.min.js') }}"></script>
        <script type="text/javascript">
            console.log('Script using second: ', jQuery.fn.jquery);
        </script>
        <script type="text/javascript">
            // Restore original jQuery:
            window.jQuery = window.$ = jQueryOriginal;
            console.log('Script using original or the only version: ', jQuery.fn.jquery);
        </script>

on select2.full.js change every "jQuery" to "jQueryTemp"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant