Sha256: 6b4aa85dc0e9d98181bbd30df1854f9900ab0a01e8e689796dad1181ab5a42b4

Contents?: true

Size: 1.47 KB

Versions: 23

Compression:

Stored size: 1.47 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
  var productId = options.productId
  var values = options.values
  var clearSelection = options.clearSelection

  function addOptions(select, productId, values) {
    $.ajax({
      type: 'GET',
      url: Spree.routes.option_values_api_v2,
      headers: Spree.apiV2Authentication(),
      dataType: 'json',
      data: {
        filter: {
          id_in: values,
          variants_product_id_eq: productId
        }
      }
    }).then(function (data) {
      select.addSelect2Options(data.data)
    })
  }

  this.select2({
    multiple: multiple,
    minimumInputLength: 1,
    ajax: {
      url: Spree.routes.option_values_api_v2,
      dataType: 'json',
      headers: Spree.apiV2Authentication(),
      data: function (params) {
        var selectedProductId = typeof (productSelect) !== 'undefined' ? productSelect.val() : null

        return {
          filter: {
            name_cont: params.term,
            variants_product_id_eq: selectedProductId
          }
        }
      },
      processResults: function(data) {
        return formatSelect2Options(data)
      }
    }
  })

  if (values && productId && !clearSelection) {
    addOptions(this, productId, values)
  }

  if (clearSelection) {
    this.val(null).trigger('change')
  }
}

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
spree_backend-4.8.4 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.8.3 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.8.2 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.8.1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.3.3 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.7.2 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.6.2 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.7.1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.7.0 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.6.1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.6.0 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.5.1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.5.0 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.3.2 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.4.1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.4.0 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.4.0.rc2 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.3.1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.4.0.rc1 app/assets/javascripts/spree/backend/option_value_picker.js
spree_backend-4.3.0 app/assets/javascripts/spree/backend/option_value_picker.js