From d4c0bb21bacf4160e3da1e342eee939c3c411393 Mon Sep 17 00:00:00 2001 From: oeN Date: Tue, 6 Jun 2017 17:39:33 +0200 Subject: [PATCH] Avoid errors on select2 init using a name selector Using a simple class selector to init select2 will throw an error if there is already an instance of select2 in the page with the same class selector. --- backend/app/assets/javascripts/spree/backend/address_states.js | 2 +- .../assets/javascripts/spree/backend/images/index.js.coffee | 2 +- backend/app/views/spree/admin/products/new.js.erb | 2 +- backend/app/views/spree/admin/promotion_actions/create.js.erb | 3 +-- backend/app/views/spree/admin/stock_locations/_form.html.erb | 2 +- .../admin/style_guide/topics/forms/_building_forms.html.erb | 2 +- backend/app/views/spree/admin/variants/new.js.erb | 2 +- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/backend/app/assets/javascripts/spree/backend/address_states.js b/backend/app/assets/javascripts/spree/backend/address_states.js index 2eef4c0985d..4005cada5cb 100644 --- a/backend/app/assets/javascripts/spree/backend/address_states.js +++ b/backend/app/assets/javascripts/spree/backend/address_states.js @@ -1,7 +1,7 @@ window.update_state = function (region, done) { 'use strict'; - var country = $('span#' + region + 'country .select2').select2('val'); + var country = $('span#' + region + 'country select.select2').select2('val'); var state_select = $('span#' + region + 'state select.select2'); var state_input = $('span#' + region + 'state input.state_name'); diff --git a/backend/app/assets/javascripts/spree/backend/images/index.js.coffee b/backend/app/assets/javascripts/spree/backend/images/index.js.coffee index 6b9524d5a0c..ffeb8fca362 100644 --- a/backend/app/assets/javascripts/spree/backend/images/index.js.coffee +++ b/backend/app/assets/javascripts/spree/backend/images/index.js.coffee @@ -10,4 +10,4 @@ $ -> url: @href success: (r) -> ($ '#images').html r - ($ '.select2').select2() + ($ 'select.select2').select2() diff --git a/backend/app/views/spree/admin/products/new.js.erb b/backend/app/views/spree/admin/products/new.js.erb index 9d6def7f2d9..375f887b867 100644 --- a/backend/app/views/spree/admin/products/new.js.erb +++ b/backend/app/views/spree/admin/products/new.js.erb @@ -1,7 +1,7 @@ $("#new_product_wrapper").html('<%= escape_javascript(render template: "spree/admin/products/new", formats: [:html], handlers: [:erb]) %>'); handle_date_picker_fields(); <% unless Rails.env.test? %> - $('.select2').select2(); + $('select.select2').select2(); <% end %> $("#table-filter").hide(); $("#admin_new_product").parent().hide(); 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 e7127c6c616..7241e5f71e3 100644 --- a/backend/app/views/spree/admin/promotion_actions/create.js.erb +++ b/backend/app/views/spree/admin/promotion_actions/create.js.erb @@ -2,7 +2,7 @@ $('#actions').append('<%= escape_javascript( render(partial: 'spree/admin/promot $('#actions .no-objects-found').hide(); $(".variant_autocomplete").variantAutocomplete(); //enable select2 functions for recently added box -$('.type-select.select2').last().select2(); +$('select.type-select.select2').last().select2(); initPromotionActions(); @@ -10,4 +10,3 @@ initPromotionActions(); $('#<%= dom_id @promotion_action %>').hide(); $('#<%= dom_id @promotion_action %>').fadeIn(); new Spree.CalculatorEditView({el: $('#<%= dom_id @promotion_action %> .js-calculator-fields')}); - diff --git a/backend/app/views/spree/admin/stock_locations/_form.html.erb b/backend/app/views/spree/admin/stock_locations/_form.html.erb index 255e7909d12..22877c4fe6a 100644 --- a/backend/app/views/spree/admin/stock_locations/_form.html.erb +++ b/backend/app/views/spree/admin/stock_locations/_form.html.erb @@ -114,7 +114,7 @@ <% content_for :head do %> <%= javascript_tag do -%> $(document).ready(function(){ - $('span#country .select2').on('change', function() { update_state(''); }); + $('span#country select.select2').on('change', function() { update_state(''); }); }); <% end -%> <% end %> diff --git a/backend/app/views/spree/admin/style_guide/topics/forms/_building_forms.html.erb b/backend/app/views/spree/admin/style_guide/topics/forms/_building_forms.html.erb index 73d43a29cb0..63e476d2a6a 100644 --- a/backend/app/views/spree/admin/style_guide/topics/forms/_building_forms.html.erb +++ b/backend/app/views/spree/admin/style_guide/topics/forms/_building_forms.html.erb @@ -78,6 +78,6 @@ diff --git a/backend/app/views/spree/admin/variants/new.js.erb b/backend/app/views/spree/admin/variants/new.js.erb index 1d8e8f7e72e..5d3afbd1ffb 100644 --- a/backend/app/views/spree/admin/variants/new.js.erb +++ b/backend/app/views/spree/admin/variants/new.js.erb @@ -1,2 +1,2 @@ $(".js-content-below-tabs").html('<%= escape_javascript(render template: 'spree/admin/variants/new', formats: [:html], handlers: [:erb]) %>'); -$(".js-content-below-tabs .select2").select2(); +$(".js-content-below-tabs select.select2").select2();