Skip to content

Better import of jQuery for the change_form that adds the jQuery.ui.t…#36

Open
Rui-Carvalho wants to merge 1 commit intoomji:masterfrom
Rui-Carvalho:Fixing-issue-35
Open

Better import of jQuery for the change_form that adds the jQuery.ui.t…#36
Rui-Carvalho wants to merge 1 commit intoomji:masterfrom
Rui-Carvalho:Fixing-issue-35

Conversation

@Rui-Carvalho
Copy link

@Rui-Carvalho Rui-Carvalho commented Jun 8, 2019

See issue 35:

The error "Uncaught TypeError: $(...).tabs is not a function" is produced when using django-tabbed-admin under the following setup:

Django = 1.10.5
django-tabbed-admin=1.0.4
DEFAULT_JQUERY_UI_JS = 'tabbed_admin/js/jquery-ui-1.11.4.min.js'
The problem is that the code in jquery-ui-1.11.4.min.js is as follows:

/*! jQuery UI - v1.11.4 - 2015-07-27
(...)*/
jQuery = jQuery \|\| django.jQuery.noConflict(false); 

and the code on django-tabbed-admin uses it this way (change_form.html):

    <script type="text/javascript">
        (function($) {
            $(window).scrollTop()
            $('#tabs').tabs({
                {% if add %}
                // when adding, don't select a tab by default, we'll do it ourselves
                // by finding the first available tab.
                selected: -1
                {% endif %}
            });
        (....)
        })(django.jQuery);
    </script>
    <!-- end admin_tabs stuff -->

To sort this out this should be what would be passed in to the IIFE instead of the (django.jQuery) as above:

    <script type="text/javascript">
        (function($) {
            (....)
        })((typeof window.jQuery == 'undefined' && typeof window.django != 'undefined')
  ? django.jQuery
  : jQuery)
    </script>
    <!-- end admin_tabs stuff -->

@coveralls
Copy link

Coverage Status

Coverage remained the same at 89.971% when pulling 430c05d on Rui-Carvalho:Fixing-issue-35 into 82cf985 on omji:master.

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

Successfully merging this pull request may close these issues.

2 participants