Skip to content

Commit

Permalink
fix customer autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
damianlegawiec committed Dec 28, 2020
1 parent c9a774e commit cff9154
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions backend/app/assets/javascripts/spree/backend/checkouts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,14 @@ function formatCustomerSelection(customer) {
return customer.email
}

// Select2-AJAX
// Searches for Users
// Used in Order -> Customer
function set_customer_search_select (selector) {
$(selector).select2({
$.fn.customerAutocomplete = function() {
this.select2({
minimumInputLength: 3,
placeholder: Spree.translations.choose_a_customer,
ajax: {
url: Spree.routes.users_api,
datatype: 'json',
data: function (params, page) {
data: function (params) {
return {
q: {
'm': 'or',
Expand All @@ -83,22 +80,19 @@ function set_customer_search_select (selector) {
token: Spree.api_key
}
},
processResults: function (data, _page) {
return { results: data['users'] }
processResults: function (data) {
return { results: data.users }
}
},
templateResult: formatCustomerResult
}).on('select2:select', function (e) {
var data = e.params.data;
formatCustomerSelection(data)
});
})
}

document.addEventListener('DOMContentLoaded', function() {
// Set up Select 2 on page ready
if ($('#customer_search').length > 0) {
set_customer_search_select('#customer_search')
}
$('#customer_search').customerAutocomplete()

if ($('#customer_autocomplete_template').length > 0) {
window.customerTemplate = Handlebars.compile($('#customer_autocomplete_template').text())
Expand Down

0 comments on commit cff9154

Please sign in to comment.