Sha256: 4113a1a5597421f6a49e9b988b627dfbcaae69e97792a1bc6958cc7a8c763035

Contents?: true

Size: 1.21 KB

Versions: 31

Compression:

Stored size: 1.21 KB

Contents

$.fn.optionValueAutocomplete = function (options) {
  /* globals Spree */
  'use strict';

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

  this.select2({
    minimumInputLength: 3,
    multiple: multiple,
    initSelection: function (element, callback) {
      $.get(Spree.routes.option_value_search, {
        ids: element.val().split(','),
        token: Spree.api_key
      }, function (data) {
        callback(multiple ? data : data[0]);
      });
    },
    ajax: {
      url: Spree.routes.option_value_search,
      datatype: 'json',
      data: function (term) {
        var productId = typeof(productSelect) !== 'undefined' ? $(productSelect).select2('val') : null;
        return {
          q: {
            name_cont: term,
            variants_product_id_eq: productId
          },
          token: Spree.api_key
        };
      },
      results: function (data) {
        return { results: data };
      }
    },
    formatResult: function (optionValue) {
      return optionValue.name;
    },
    formatSelection: function (optionValue) {
      return optionValue.name;
    }
  });
};

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
spree_backend-3.1.14 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.13 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.12 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.11 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.10 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.9 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.8 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.7 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.6 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.5 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.4 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.3 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.2 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.0.10 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.0 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.0.rc4 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.0.9 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.0.rc3 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.1.0.rc2 app/assets/javascripts/spree/backend/option_value_picker.js