Sha256: 0ed7963f4307055b288365d06a4b69828584dfaeff8f5683cacfeec6bc3da337

Contents?: true

Size: 1.24 KB

Versions: 13

Compression:

Stored size: 1.24 KB

Contents

$.fn.optionValueAutocomplete = function (options) {
  'use strict';

  // Default options
  options = options || {}
  var multiple = typeof(options['multiple']) !== 'undefined' ? options['multiple'] : true;
  var productSelect = options['productSelect'];

  function formatOptionValue(option_value) {
    return Select2.util.escapeMarkup(option_value.name);
  }

  this.select2({
    minimumInputLength: 3,
    multiple: multiple,
    initSelection: function (element, callback) {
      $.get(Spree.routes.option_value_search, {
        ids: element.val().split(','),
      }, function (data) {
        callback(multiple ? data : data[0]);
      });
    },
    ajax: {
      url: Spree.routes.option_value_search,
      datatype: 'json',
      data: function (term, page) {
        // Note: This doesn't work. variants_product_id isn't an allowed filter
        var productId = typeof(productSelect) !== 'undefined' ? $(productSelect).select2('val') : null;
        return {
          q: {
            name_cont: term,
            variants_product_id_eq: productId
          },
        };
      },
      results: function (data, page) {
        return { results: data };
      }
    },
    formatResult: formatOptionValue,
    formatSelection: formatOptionValue
  });
};

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
solidus_backend_devise_token_auth-2.8.0.alpha.14 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.13 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.12 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.11 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.10 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.9 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.8 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.7 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.6 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.5 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.4 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.3 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend_devise_token_auth-2.8.0.alpha.2 app/assets/javascripts/spree/backend/option_value_picker.js