2

I've done an autocomplete list using typeahead (0.9.3) and bootstrap-tokeninput.

The use case is to select many recipients in a single input. (For example: when you select many users to send them a message on facebook)

Here what I've done so far (using rails):

conversation controller

def new
  @users = User.all
  respond_to do |format|
    format.html
    format.json { render json: @users }
  end
end

conversations.js

$(document).ready(function() {
  $("#conversation_recipients").tokenfield({
    typeahead: {
      prefetch: "/conversations/new.json",
      valueKey: 'username',
      template: '<img src="{{avatar.url}}"</img><span>{{username}}</span>',
      engine: Hogan
    }
  });
})

What I am trying to do is to remove already selected items from the @users list.

I don't know if I have to do it by removing selected users with js using the bootstrap-tokeninput Events api (maybe the beforeCreateToken event could be useful) and manipulating the json on this event or if there is another way to do it...

Many thanks for your suggestion.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.