Sha256: dfb0d92526a69467a597e1850e88d39c5bddb527732f3210a6998dcae5b701ee

Contents?: true

Size: 1.2 KB

Versions: 44

Compression:

Stored size: 1.2 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_values_api, {
        ids: element.val().split(','),
        token: Spree.api_key
      }, function (data) {
        callback(multiple ? data : data[0]);
      });
    },
    ajax: {
      url: Spree.routes.option_values_api,
      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

44 entries across 44 versions & 1 rubygems

Version Path
spree_backend-3.4.6 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.2.9 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.6.6 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.6.5 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.6.4 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.6.3 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.6.2 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.6.1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.6.0 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.5.0 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.3.6 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.2.8 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.6.0.rc1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.5.0.rc2 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.5.0.rc1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.4.5 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.3.5 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.4.4 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.4.3 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-3.3.4 app/assets/javascripts/spree/backend/option_value_picker.js