Sha256: 5184b66475b9bfe91db922938dadfb161a1006aa1b6282c4a0d2c3edc80fc4c7

Contents?: true

Size: 1.23 KB

Versions: 17

Compression:

Stored size: 1.23 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.pathFor('api/option_values'), {
        ids: element.val().split(','),
        token: Spree.api_key
      }, function (data) {
        callback(multiple ? data : data[0]);
      });
    },
    ajax: {
      url: Spree.pathFor('api/option_values'),
      datatype: 'json',
      data: function (term, page) {
        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

17 entries across 17 versions & 2 rubygems

Version Path
solidus_backend-4.4.1 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-4.4.0 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-4.3.4 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-4.2.4 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-4.3.3 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_friendly_promotions-1.0.0 app/javascript/solidus_friendly_promotions/jquery/option_value_picker.js
solidus_backend-4.3.2 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_friendly_promotions-1.0.0.rc.3 app/javascript/solidus_friendly_promotions/jquery/option_value_picker.js
solidus_backend-4.3.1 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-4.3.0 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_friendly_promotions-1.0.0.rc.2 app/javascript/solidus_friendly_promotions/jquery/option_value_picker.js
solidus_friendly_promotions-1.0.0.rc.1 app/javascript/solidus_friendly_promotions/jquery/option_value_picker.js
solidus_friendly_promotions-1.0.0.pre app/javascript/solidus_friendly_promotions/jquery/option_value_picker.js
solidus_backend-4.2.3 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-4.2.2 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-4.2.1 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-4.2.0 app/assets/javascripts/spree/backend/option_value_picker.js