Koha/koha-tmpl/intranet-tmpl/prog/js/select2.js
Owen Leonard ff7318c62e Bug 27124: JS error "select2Width is not defined"
This patch changes the default width paramter passed to the
select2 plugin. This allows the basic MARC editor's Select2
widgets to be styled differently than on other pages.

To test, apply the patch and view various pages where the select2 plugin
is used:

 - Basic MARC editor
 - Items edit
 - Batch item edit
 - Authority editor

In each case check that the Select2 plugin works correctly to style
fields like collection code and home library.

On the basic MARC editor page these <select>s should have a width
that adjusts as the browser window changes. On other pages the width
should be fixed.

Check the browser console and confirm that there are no JavaScript
errors.

Update: Thanks to Julian for the suggested optimization

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2020-12-21 10:07:40 +01:00

39 lines
1.4 KiB
JavaScript

/* global __ */
$.fn.select2.defaults.set("allowClear", true);
$.fn.select2.defaults.set("placeholder", "");
$.fn.select2.defaults.set("width", "element" );
// 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;
return __("Please delete %d character(s)").format(n);
},
inputTooShort:function(e){
var n = e.min - e.input.length;
return __("Please enter %n or more characters").format(n);
},
formatResult: function(item) {
return $('<div>', {title: item.element[0].title}).text(item.text);
},
loadingMore:function(){ return __("Loading more results…"); },
maximumSelected:function(e){
return __("You can only select %s item(s)").format(e.max);
},
noResults:function(){return __("No results found"); },
searching:function(){return __("Searching…"); },
removeAllItems:function(){return __("Remove all items"); },
removeItem:function(){return __("Remove item"); }
});
$(document).ready(function(){
$(".select2").select2();
$(".select2").on("select2:clear", function () {
$(this).on("select2:opening.cancelOpen", function (evt) {
evt.preventDefault();
$(this).off("select2:opening.cancelOpen");
});
});
});