From 4def3f9f22687144328c7547bbe10027eed0d96e Mon Sep 17 00:00:00 2001 From: Alessio Rocco Date: Thu, 19 May 2016 17:05:42 +0200 Subject: [PATCH 1/3] Add spreeSelect2 js function to share select2 options --- .../javascripts/spree/backend/spree-select2.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/app/assets/javascripts/spree/backend/spree-select2.js b/backend/app/assets/javascripts/spree/backend/spree-select2.js index 23f45319983..871f5e29ee6 100644 --- a/backend/app/assets/javascripts/spree/backend/spree-select2.js +++ b/backend/app/assets/javascripts/spree/backend/spree-select2.js @@ -1,11 +1,17 @@ //= require select2 -jQuery(function($) { - // Make select beautiful - $('select.select2').select2({ +$.fn.spreeSelect2 = function () { + 'use strict'; + + this.select2({ allowClear: true, dropdownAutoWidth: true, minimumResultsForSearch: 8 - }); + }) +} + +jQuery(function($) { + // Make select beautiful + $('select.select2').spreeSelect2(); function format_taxons(taxon) { new_taxon = taxon.text.replace('->', '') From 048b488d92bb3b7cb79801099c225d6a313c7eb3 Mon Sep 17 00:00:00 2001 From: Alessio Rocco Date: Thu, 19 May 2016 17:06:14 +0200 Subject: [PATCH 2/3] Fix select2 inputs for promotion rules --- backend/app/views/spree/admin/promotion_rules/create.js.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/app/views/spree/admin/promotion_rules/create.js.erb b/backend/app/views/spree/admin/promotion_rules/create.js.erb index b0adb281c57..0aefa9cce19 100644 --- a/backend/app/views/spree/admin/promotion_rules/create.js.erb +++ b/backend/app/views/spree/admin/promotion_rules/create.js.erb @@ -3,6 +3,7 @@ $('#rules .no-objects-found').hide(); $('.product_picker').productAutocomplete(); $('.user_picker').userAutocomplete(); +$('select.select2').spreeSelect2(); $('#promotion_rule_type').html('<%= escape_javascript options_for_promotion_rule_types(@promotion) %>'); $('#promotion_rule_type').select2(); From e321cf8ad026696e5e4148b964586952fe5adb99 Mon Sep 17 00:00:00 2001 From: Alessio Rocco Date: Thu, 19 May 2016 17:06:49 +0200 Subject: [PATCH 3/3] Use spreeSelect2 for promotion actions selects --- backend/app/views/spree/admin/promotion_actions/create.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/views/spree/admin/promotion_actions/create.js.erb b/backend/app/views/spree/admin/promotion_actions/create.js.erb index 9700fc67170..e12fc95a7ff 100644 --- a/backend/app/views/spree/admin/promotion_actions/create.js.erb +++ b/backend/app/views/spree/admin/promotion_actions/create.js.erb @@ -3,7 +3,7 @@ $('#actions .no-objects-found').hide(); $(document).ready(function(){ $(".variant_autocomplete").variantAutocomplete(); //enable select2 functions for recently added box - $('.type-select.select2').last().select2(); + $('.type-select.select2').last().spreeSelect2(); }); initProductActions();