diff --git a/smart_selects/static/smart-selects/admin/js/chainedm2m.js b/smart_selects/static/smart-selects/admin/js/chainedm2m.js index 46adab4..f3eb7d8 100755 --- a/smart_selects/static/smart-selects/admin/js/chainedm2m.js +++ b/smart_selects/static/smart-selects/admin/js/chainedm2m.js @@ -45,17 +45,6 @@ } } - // SelectBox is a global var from djangojs "admin/js/SelectBox.js" - // Clear cache to avoid the elements duplication - if (typeof SelectBox !== 'undefined') { - if (typeof SelectBox.cache[cache_to] !== 'undefined') { - SelectBox.cache[cache_to].splice(0); - } - if (typeof SelectBox.cache[cache_from] !== 'undefined') { - SelectBox.cache[cache_from].splice(0); - } - } - if (!val || val === '') { $selectField.html(''); $selectedto.html(''); @@ -111,6 +100,18 @@ }); $selectField.html(options); + + // SelectBox is a global var from djangojs "admin/js/SelectBox.js" + // Clear cache to avoid the elements duplication + if (typeof SelectBox !== 'undefined') { + if (typeof SelectBox.cache[cache_to] !== 'undefined') { + SelectBox.cache[cache_to].splice(0); + } + if (typeof SelectBox.cache[cache_from] !== 'undefined') { + SelectBox.cache[cache_from].splice(0); + } + } + if ($selectedto.length) { $selectedto.html(selectedoptions); // SelectBox is a global var from djangojs "admin/js/SelectBox.js"