 emptyOrWhitespaceRegex = RegExp(/^\s*$/)
+DELETE_KEYCODE = 8
+ENTER_KEYCODE = 13
+
 
 class FormbuilderModel extends Backbone.DeepModel
   sync: -> # noop

    'click .js-remove-option': 'removeOption'
    'click .js-default-updated': 'defaultUpdated'
    'input .option-label-input': 'forceRender'

  initialize: (options) ->
    {@parentView} = options


    @model.set Formbuilder.options.mappings.OPTIONS, options
    @model.trigger "change:#{Formbuilder.options.mappings.OPTIONS}"

    # let's focus on the newly added element...
    targetSlot = 1 * (if i > -1 then i + 1 else options.length - 1)
    ($(".edit-response-field .sortableParentContainer .option .option-label-input")[targetSlot]).focus()

    @forceRender()

  removeOption: (e) ->
    $el = $(e.currentTarget)
    index = @$el.find(".js-remove-option").index($el)
    @removeOptionAtIndex(index)

  removeOptionAtIndex: (index) ->
    options = @model.get Formbuilder.options.mappings.OPTIONS
    options.splice index, 1
    @model.set Formbuilder.options.mappings.OPTIONS, options
