Skip to content

Commit

Permalink
squash Improve variantAutocomplete to be more reusable
Browse files Browse the repository at this point in the history
Make variantAutocomplete backwards compatible. Users can still pass an
object of parameters, null or nothing, if the former is done, a
console.warn deprecation warning is shown.
  • Loading branch information
RyanofWoods committed Dec 22, 2022
1 parent e2f7fca commit fd61689
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
/**
* Make the element a select2 dropdown used for finding Variants. By default, the search term will be
* passed to the defined Spree::Config.variant_search_class by the controller with its defined scope.
* @param {Object} options Options
* @param {Object|undefined|null} options Options
* @param {Function|undefined} options.searchParameters Returns a hash object for params to merge on the select2 ajax request
* Accepts an argument of the select2 search term. To use Ransack, define
* variant_search_term as a falsy value, and q as the Ransack query. Note,
* you need to ensure that the attributes are allowed to be Ransacked.
*/
$.fn.variantAutocomplete = function(options = {}) {
$.fn.variantAutocomplete = function(options) {
function extraParameters(term) {
if (typeof(options['searchParameters']) === 'function') {
return options['searchParameters'](term)
if (typeof(options) === 'object') {
if (typeof(options['searchParameters']) === 'function') {
return options['searchParameters'](term)
} else {
console.warn("Solidus deprecation: Passing an object of parameters to variantAutocomplete is deprecated. Instead, on the options object, please declare `searchParameters` as a function returning the parameters.")
}
}

return {}
Expand Down

0 comments on commit fd61689

Please sign in to comment.