   template: 'generic/text_input'
 
   initialize: ->
-    @listenTo @model, 'change', @updateHtml
+    @listenTo @model, 'change', @_updateHtml
 
   focusInput: ->
-    _.defer => @$inputField().focus()
+    _.defer => @ui.inputField.focus()
 
   parseKeyDown: (e) ->
     eventHandled = false

      e.preventDefault()
      e.stopPropagation()

  updateModel: -> @model.set text: @$inputField().val()
  updateHtml: ->
    if @model.get('text') != @$inputField().val()
      @$inputField().val(@model.get('text'))

  enable: -> @$inputField().prop 'disabled', false
  disable: ->@$inputField().prop 'disabled', true

  $inputField: -> @$('.typeahead')

Backbone.Factlink ||= {}
class Backbone.Factlink.TextInputView extends Backbone.Marionette.ItemView
  events:
    'keydown .typeahead': 'parseKeyDown'
    'keyup .typeahead': '_updateModel'
    'input .typeahead': '_updateModel'

  triggers:
    'focus .typeahead': 'focus'
    'blur .typeahead': 'blur'

  ui:
    inputField: '.typeahead'

  templateHelpers: =>
    placeholder: @options.placeholder
