     @searchInput.on 'blur', @onSearchInputBlur
 
   enableAutocomplete: ->
+    return if @autocomplete
+
     dropdownMenu = @dropdown.find('.dropdown-menu')
     _this = @
+    loading = false
+
     @searchInput.glDropdown
         filterInputBlur: false
         filterable: true

        search:
          fields: ['text']
        data: (term, callback) ->
          $.get(_this.autocompletePath, {
              project_id: _this.projectId
              project_ref: _this.projectRef
              term: term

    @dropdown.dropdown('toggle')

  onSearchInputKeyDown: (e) =>
    switch e.keyCode
      when KEYCODE.BACKSPACE
        if e.currentTarget.value is ''
          @removeLocationBadge()
          @searchInput.focus()
      when KEYCODE.ESCAPE
        if @badgePresent()
        else
          @restoreOriginalState()

          # If after restoring there's a badge
          @disableAutocomplete() if @badgePresent()
      else
        if @badgePresent()
          @disableAutocomplete()
        else
          @enableAutocomplete()

    # Avoid falsy value to be returned
    return

  onSearchInputFocus: =>
    @wrap.addClass('search-active')
