         id: (item) -> item.id
         initSelection: (el, cb) -> cb(userRoles)
         multiple: true
-        formatResult: (item, $container, query) -> $('<div></div>').append(item.text)
+        formatSelection: (user) -> "<div class='#{user.state}'>#{user.text}</div>"
+        formatResult: (item, $container, query) -> $("<div></div>").append(item.text)
         ajax:
           url: "//#{settings.cnxauthoring.host}:#{settings.cnxauthoring.port}/users/search"
           dataType: 'json'

                return user
            }


    displayName: (fullname, id) ->
      if fullname isnt null
        return "#{fullname} (#{id})"

        if typeof item is 'string'
          return users[item]
        else
          user = {id: item.id, text: @displayName(item.fullname, item.id), state: 'pending'}
          if item.hasAccepted isnt null
            user.state = if item.hasAccepted then 'accepted' else 'rejected'
          users["#{user.id}"] = user
          return user

