Bug 25727: Fix default values
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sat, 13 Jun 2020 12:08:11 +0000 (14:08 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 24 Aug 2020 09:19:03 +0000 (11:19 +0200)
The way we defined the default values does not longer work (?)
Using
  $.fn.select2.defaults.set
instead of
  jQuery.extend($.fn.select2.defaults, {
fixes the problem.

It restores the allowClear setting.

There is a change in the behavior here, the selection opens when the
clear button is clicked. That is coming from a change in Select2
apparently. We may want to hack something to restore the precedent
behaviour.

This patch also removes the redefinition of the width. It seems that the
issue that this code was trying to correct is now fixed.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/intranet-tmpl/prog/en/includes/select2.inc

index e51ebfd..dd1df60 100644 (file)
@@ -5,27 +5,11 @@
 [% Asset.css("css/select2.css") | $raw %]
 <!-- select2.inc -->
 <script>
-  jQuery.extend($.fn.select2.defaults, {
-    allowClear: true,
-    width: function() {
-      var width = this.element.outerWidth();
+  $.fn.select2.defaults.set("allowClear", true);
+  $.fn.select2.defaults.set("placeholder", "");
 
-      // 18 is the width of .select2-arrow
-      width -= 18;
-
-      if (this.allowClear) {
-        // 42 is the margin-right of .select2-chosen when allowClear is true
-        width += 42;
-      } else {
-        // 26 is the margin-right of .select2-chosen when allowClear is false
-        width += 26;
-      }
-
-      return width;
-    },
-
-    // Internationalization
-    language: {
+  // Internationalization
+  $.fn.select2.defaults.set("language", {
       errorLoading:function(){return"The results could not be loaded."},
       inputTooLong:function(e){
           var n = e.input.length - e.max;
@@ -46,7 +30,6 @@
       searching:function(){return _("Searching…")},
       removeAllItems:function(){return _("Remove all items")},
       removeItem:function(){return _("Remove item")}
-    }
-  });
+    });
 </script>
 <!-- / select2.inc -->