Sha256: a55e8291e206573a48345074876996f1254b71534f64e9088d31f42585c5802f

Contents?: true

Size: 820 Bytes

Versions: 3

Compression:

Stored size: 820 Bytes

Contents

$.fn.productAutocomplete = function() {
  if (Spree.routes) {
    this.select2({
      minimumInputLength: 1,
      multiple: true,
      initSelection: function(element, callback) {
        $.get(Spree.routes.product_search, { ids: element.val() }, function(data) { 
          callback(data)
        })
      },
      ajax: {
        url: Spree.routes.product_search,
        datatype: 'json',
        data: function(term, page) {
          return { q: term }
        },
        results: function(data, page) {
          return { results: data }
        }
      },
      formatResult: function(product) {
        return product.name;
      },
      formatSelection: function(product) {
        return product.name;
      }
    });
  }
}

$(document).ready(function () {
  $('.product_picker').productAutocomplete();
})

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_promo-1.3.5 app/assets/javascripts/admin/product_picker.js
spree_promo-1.3.4 app/assets/javascripts/admin/product_picker.js
spree_promo-1.3.3 app/assets/javascripts/admin/product_picker.js