Sha256: f9d8cdd9f91c88237ffbb602d359a06cdff3c2272d7027267e2f902be524961a

Contents?: true

Size: 1.3 KB

Versions: 40

Compression:

Stored size: 1.3 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(','),
        token: Spree.api_key
      }, 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
          },
          token: Spree.api_key
        };
      },
      results: function (data, page) {
        return { results: data };
      }
    },
    formatResult: formatOptionValue,
    formatSelection: formatOptionValue
  });
};

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
solidus_backend-2.10.5 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.10.3 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.10.2 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.9.6 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.8.6 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.10.1 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.9.5 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.10.0 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.9.4 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.6.6 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.7.4 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.8.5 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.9.3 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.9.2 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.10.0.beta1 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.7.3 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.6.5 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.5.2 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.9.1 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-2.9.0 app/assets/javascripts/spree/backend/option_value_picker.js