Skip to content

Commit

Permalink
Fixes user selector [Object object] bug
Browse files Browse the repository at this point in the history
  • Loading branch information
toomuchpete committed Mar 28, 2024
1 parent 61f438f commit 80c2ff1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ def search
format.json do
results = { :suggestions => [], :data => [], :query => params[:query] }
user_search(params[:query]).each do |user|
if params[:exclude] && params[:exclude].include?(user._id.to_s)
next
end
results[:suggestions] << "#{user.firstname} #{user.lastname} [#{user.email_address}]"
results[:data] << {
'_id' => user._id,
'_id' => user._id.to_s,
'firstname' => user.firstname,
'lastname' => user.lastname,
'email_address' => user.email_address,
Expand Down
6 changes: 6 additions & 0 deletions app/views/_user_multiselect.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
%input.span3.new-user{type: 'text'}
%i.icon-plus

- user_search_params = {}
- if local_assigns[:exclude].nil? == false
- user_search_params["exclude"] = exclude.map(&:_id)


- content_for :page_scripts do
:javascript
var user_search_params = #{user_search_params.to_json};
= javascript_include_tag '/javascripts/jquery.autocomplete.js'
= javascript_include_tag '/javascripts/userSelector.js'

Expand Down
4 changes: 4 additions & 0 deletions public/javascripts/userSelector.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
$(function(){
// Autocomplete
$(".user-multi-select").each(function(){
if (typeof user_search_params !== 'undefined') {
console.log(user_search_params);
}
var ums = $(this);
var userAutocomplete = ums.find("input.new-user").autocomplete({
serviceUrl:'/users/search.json',
params: user_search_params,
minChars: 3,
maxHeight: 400,
width: 350,
Expand Down

0 comments on commit 80c2ff1

Please sign in to comment.