-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search select and multiple? #385
Comments
hi @JoDaBaRo! Thanks for noticing that, I haven't faced this situation before, but I could confirm and reproduce the behavior you describe. I think you found a clever workaround that proves this change should not be that hard to implement if you can figure out how to deal with the "initial load" of the multiple values. I reviewed the code and indeed, the multiple option is not supported by the search select input, however, I think it could be a worthy addition. I haven't got the time to implement it myself but I'd gladly review it if you or someone else wants to implement it. |
@rjherrera I don't think I have the time to make a proper PR but I did dig around and I believe I found the culprit here, looks like the
Right now I have these methods overwritten in an active admin concern that I'm calling on the admin form I need it for, It doesn't seem to be breaking anything but I haven't ran any specs on it so can't be certain about it |
I've made it work using the default In your form: f.input :recipients, as: :select, multiple: true, input_html: { 'data-ajax--url': list_recipients_admin_message_path(resource) } And in your member_action :list_recipients, method: :get do
term = params[:term] || ''
return render json: { results: [] } if term.size < 2
query = User.where('users.nickname ILIKE ?', "%#{term}%").uniq
select_keys = [:id, :nickname]
output_keys = [:id, :text]
results = query.pluck(*select_keys).map { |pa| Hash[output_keys.zip(pa)] }
render json: { results: results }
end Some links that helped me :
This solution requires that you write you own search and you won't have as many free options as you'd have with |
FYI Also facing this issue. Is there another known workaround? |
Hello, first of all big fan of the gem, it saves a lot of headaches.
I would like to ask if there's a proper way to implement ajax search into a multiple select field while using the search_select plugin
I've tried
But it stays as a single selection input, now I managed to circumvent it by adding the multiple flag trough html options
And this works like a charm when the field is empty, both the multi select and ajax search work fine and it persists correctly, however as I re enter the form to edit it the field only displays one of the options, I've tried overwriting the selected values trough html options as well but it doesn't seem to work, any ideas?
The text was updated successfully, but these errors were encountered: