Sha256: eb8367fd95bee59fb085fe475aca809b059fd15d017d84c2cdab58f3ef448dba

Contents?: true

Size: 1.18 KB

Versions: 10

Compression:

Stored size: 1.18 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'];

  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) {
        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: function (option_value) {
      return option_value.name;
    },
    formatSelection: function (option_value) {
      return option_value.name;
    }
  });
};

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
solidus_backend-1.2.0 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-1.2.0.rc2 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-1.1.2 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-1.2.0.rc1 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-1.2.0.beta1 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-1.1.1 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-1.1.0 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-1.1.0.pre2 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-1.1.0.pre1 app/assets/javascripts/spree/backend/option_value_picker.js
solidus_backend-1.1.0.beta1 app/assets/javascripts/spree/backend/option_value_picker.js