Skip to content

Commit

Permalink
Don't call select2 for user_picker in spree_promo.js if that element …
Browse files Browse the repository at this point in the history
…does not exist

Fixes spree#2245
  • Loading branch information
radar committed Nov 28, 2012
1 parent 0424051 commit 37c6430
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions promo/app/assets/javascripts/admin/spree_promo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@ function cleanUsers(data) {
}

$(document).ready(function() {
$('.user_picker').select2({
minimumInputLength: 1,
multiple: true,
initSelection: function(element, callback) {
$.get(Spree.routes.user_search, { ids: element.val() }, function(data) {
callback(cleanUsers(data))
})
},
ajax: {
url: Spree.routes.user_search,
datatype: 'json',
data: function(term, page) {
return { q: term }
if ($('user_picker').length > 0) {
$('.user_picker').select2({
minimumInputLength: 1,
multiple: true,
initSelection: function(element, callback) {
$.get(Spree.routes.user_search, { ids: element.val() }, function(data) {
callback(cleanUsers(data))
})
},
results: function(data, page) {
return { results: cleanUsers(data) }
ajax: {
url: Spree.routes.user_search,
datatype: 'json',
data: function(term, page) {
return { q: term }
},
results: function(data, page) {
return { results: cleanUsers(data) }
}
},
formatResult: function(user) {
return user.email;
},
formatSelection: function(user) {
return user.email;
}
},
formatResult: function(user) {
return user.email;
},
formatSelection: function(user) {
return user.email;
}
});
});
}
})

0 comments on commit 37c6430

Please sign in to comment.