       results: (data, page) ->
         results: data.map (term) -> {id: term, text: term}
 
+  _setup_select2_delete_callback field_id, (tag) ->
+    tag.children("div").children("div").html()?.trim()
+
   $(field_id).ready ->
     values = []
 

# You can use CoffeeScript in this file: http://coffeescript.org/

artifact_search_fields = ['apps', 'tags', 'license', 'hash', 'formats']

initialize_select = (field_id, url) ->
  return if not $(field_id)[0]

      values.push {id: value, text: value} if value != ''

    $(field_id).select2 'data', values

select_for_http_links = (id) ->

  # Puts http:// in front of selection and sets obj.id equal to obj.text
  format = (object, container) ->
    text = escapeHTML(object.text)
    # Assume a url has been entered and stick a http:// in front if it's not there
    if not object.text.match(/^http[s]?\:\/\//)
       text = 'http://' + text
    else
      text

    object.text = object.id = text

  if $(id)[0]
    $(id)?.select2
      minimumResultsForSearch: Infinity
      tags: []
      width: '80%'
      tokenSeparators: [',', ';']

      formatNoMatches: ->
        "Enter a valid URL"

      formatResult: format
      formatSelection: format

    _setup_select2_delete_callback id, (tag) ->
      tag.children("div").html()?.trim()

initialize_editor = ->

