From 56a0aabc58a3475912894523cc92757153b967bd Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 29 Sep 2017 15:52:50 +0200 Subject: [PATCH] Bug 18422: (QA follow-up) Check if select2 is available before using it cataloging.js might not always be loaded with select2.js, so we should check its availability to prevent JS errors Signed-off-by: Julian Maurice Signed-off-by: Jonathan Druart --- koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js index eedac25377..65e7e26ef6 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js @@ -77,16 +77,20 @@ function ExpandField(index) { var Select2Utils = { removeSelect2: function(element) { - var selects = element.getElementsByTagName('select'); - for (var i=0; i < selects.length; i++) { - $(selects[i]).select2('destroy'); + if ($.fn.select2) { + var selects = element.getElementsByTagName('select'); + for (var i=0; i < selects.length; i++) { + $(selects[i]).select2('destroy'); + } } }, initSelect2: function(element) { - var selects = element.getElementsByTagName('select'); - for (var i=0; i < selects.length; i++) { - $(selects[i]).select2(); + if ($.fn.select2) { + var selects = element.getElementsByTagName('select'); + for (var i=0; i < selects.length; i++) { + $(selects[i]).select2(); + } } } }; -- 2.11.4.GIT