       scope: @scopeInputEl.val()
 
       # Location badge
-      _location: $.trim(@locationText.text())
+      _location: @locationText.text()
     }
 
   bindEvents: ->
+    @searchInput.on 'keydown', @onSearchInputKeyDown
     @searchInput.on 'keyup', @onSearchInputKeyUp
     @searchInput.on 'click', @onSearchInputClick
     @searchInput.on 'focus', @onSearchInputFocus


  saveOriginalState: ->
    @originalState = @serializeState()

  createAutocomplete: ->
    @searchInput.glDropdown

  onDropdownOpen: (e) =>
    @dropdown.dropdown('toggle')

  onSearchInputKeyDown: =>
    # Saves last length of the entered text
    @saveTextLength()

  onSearchInputKeyUp: (e) =>
    switch e.keyCode
      when KEYCODE.BACKSPACE
        # when trying to remove the location badge
        if @lastTextLength is 0 and @badgePresent()
            @removeLocationBadge()

        # When removing the last character and no badge is present
        if @lastTextLength is 1 and !@badgePresent()
          @disableAutocomplete()
      when KEYCODE.ESCAPE
        if @badgePresent()
