Sha256: 3cd661c38339f4f82ba7644191a86df8e12989c06e46eb500c624e0b893988f8

Contents?: true

Size: 786 Bytes

Versions: 13

Compression:

Stored size: 786 Bytes

Contents

$.fn.taxonAutocomplete = function() {
  'use strict'

  function formatTaxonList(values) {
    return values.map(function (obj) {
      return {
        id: obj.id,
        text: obj.pretty_name
      }
    })
  }

  this.select2({
    multiple: true,
    placeholder: Spree.translations.taxon_placeholder,
    minimumInputLength: 2,
    ajax: {
      url: Spree.routes.taxons_api,
      dataType: 'json',
      data: function (params) {
        return {
          q: {
            name_cont: params.term,
          },
          token: Spree.api_key
        }
      },
      processResults: function(data) {
        return {
          results: formatTaxonList(data.taxons)
        }
      }
    }
  })
}

$(document).ready(function () {
  $('#product_taxon_ids').taxonAutocomplete()
})

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spree_backend-4.2.7 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.6 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.3.0.rc1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.5 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.4 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.3.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.3 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.2 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.1 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.0 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.0.rc5 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.0.rc4 app/assets/javascripts/spree/backend/taxon_autocomplete.js
spree_backend-4.2.0.rc3 app/assets/javascripts/spree/backend/taxon_autocomplete.js