omji / django-tabbed-admin

Easily add tabs to django admin forms
BSD 3-Clause "New" or "Revised" License
63 stars 68 forks source link

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

Open Rui-Carvalho opened 5 years ago

Rui-Carvalho commented 5 years ago

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 commented 5 years ago

Coverage Status

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