Sha256: 91677bc0e7084fae58e96df5656c9a154068bfccf39f0cb621c234b46c4bfa88

Contents?: true

Size: 744 Bytes

Versions: 4

Compression:

Stored size: 744 Bytes

Contents

$.fn.productAutocomplete = function() {
  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

4 entries across 4 versions & 1 rubygems

Version Path
spree_promo-1.3.2 app/assets/javascripts/admin/product_picker.js
spree_promo-1.3.1 app/assets/javascripts/admin/product_picker.js
spree_promo-1.3.0 app/assets/javascripts/admin/product_picker.js
spree_promo-1.3.0.rc2 app/assets/javascripts/admin/product_picker.js