#29264: JS loading order in Admin-Change_form changes from model to model
-------------------------------------------+------------------------
               Reporter:  yarharel         |          Owner:  nobody
                   Type:  Bug              |         Status:  new
              Component:  Template system  |        Version:  2.0
               Severity:  Normal           |       Keywords:
           Triage Stage:  Unreviewed       |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------
 In _changeform_view
 
[https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1538],
 the self.media and the adminForm media is being merged and then passed
 into rendering.
 This line merges two lists of css and js.
 The order of JS is important, and in this case (using Autocomplete-light
 package), it creates sitations where one change_form would load fine and
 another not to work fine because the js order changed.

 In my project, autocomplete-light package should load before admin (in
 INSTALLED_APPS), but the MediaWidget merge function
 [https://github.com/django/django/blob/master/django/forms/widgets.py#L99]
 switches the order sometimes.
 self.media always contains regular admin js and css while adminForm.media
 contains autocomplete-light js
 One example of result (`media = self.media + adminForm.media`)
 {{{
 self.media._js:
 <class 'list'>: ['admin/js/vendor/jquery/jquery.js',
 'admin/js/jquery.init.js', 'admin/js/core.js',
 'admin/js/admin/RelatedObjectLookups.js', 'admin/js/actions.js',
 'admin/js/urlify.js', 'admin/js/prepopulate.js',
 'admin/js/vendor/xregexp/xregexp.js']

 adminForm.media._js:
 <class 'list'>: ['autocomplete_light/jquery.init.js',
 'autocomplete_light/autocomplete.init.js',
 'autocomplete_light/vendor/select2/dist/js/select2.full.js',
 'autocomplete_light/vendor/select2/dist/js/i18n/en.js',
 'autocomplete_light/forward.js', 'autocomplete_light/select2.js',
 'admin/js/vendor/jquery/jquery.js', 'admin/js/jquery.init.js',
 'admin/js/calendar.js', 'admin/js/admin/DateTimeShortcuts.js']

 merge result -> media._js:
 <class 'list'>: ['autocomplete_light/jquery.init.js',
 'autocomplete_light/autocomplete.init.js',
 'autocomplete_light/vendor/select2/dist/js/select2.full.js',
 'autocomplete_light/vendor/select2/dist/js/i18n/en.js',
 'autocomplete_light/forward.js', 'autocomplete_light/select2.js',
 'admin/js/vendor/jquery/jquery.js', 'admin/js/jquery.init.js',
 'admin/js/core.js', 'admin/js/admin/RelatedObjectLookups.js',
 'admin/js/actions.js', 'admin/js/urlify.js', 'admin/js/prepopulate.js',
 'admin/js/vendor/xregexp/xregexp.js', 'admin/js/calendar.js',
 'admin/js/admin/DateTimeShortcuts.js']
 }}}

 other change_form page:
 {{{
 self.media._js:
 <class 'list'>: ['admin/js/vendor/jquery/jquery.js',
 'admin/js/jquery.init.js', 'admin/js/core.js',
 'admin/js/admin/RelatedObjectLookups.js', 'admin/js/actions.js',
 'admin/js/urlify.js', 'admin/js/prepopulate.js',
 'admin/js/vendor/xregexp/xregexp.js']

 adminForm.media._js:
 <class 'list'>: ['autocomplete_light/jquery.init.js',
 'autocomplete_light/autocomplete.init.js',
 'autocomplete_light/vendor/select2/dist/js/select2.full.js',
 'autocomplete_light/vendor/select2/dist/js/i18n/en.js',
 'autocomplete_light/forward.js', 'autocomplete_light/select2.js']

 merge result -> media._js:
 <class 'list'>: ['admin/js/vendor/jquery/jquery.js',
 'admin/js/jquery.init.js', 'admin/js/core.js',
 'admin/js/admin/RelatedObjectLookups.js', 'admin/js/actions.js',
 'admin/js/urlify.js', 'admin/js/prepopulate.js',
 'admin/js/vendor/xregexp/xregexp.js', 'autocomplete_light/jquery.init.js',
 'autocomplete_light/autocomplete.init.js',
 'autocomplete_light/vendor/select2/dist/js/select2.full.js',
 'autocomplete_light/vendor/select2/dist/js/i18n/en.js',
 'autocomplete_light/forward.js', 'autocomplete_light/select2.js']
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29264>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.8386c08653c2b63fc289323b9310814f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to