     @setCallback states[index + 1].bind @, @toggleState.bind @
 
   toggleState:(err)->
+
     {states} = @getOptions()
     nextState = states[@stateIndex + 2] or states[0]
     unless err

  triggerClick:()-> @doOnSubmit()

class KDToggleButton extends KDButtonView
  constructor:(options = {},data)->
    options = $.extend
      dataPath : null          # a JsPath String
      states   : []            # an Array of Objects in form of stateName : callback key/value pairs

    @attachListener()
    
  attachListener:->

    {dataPath} = @getOptions()
    if dataPath
      @getData().on dataPath, =>
        @setState dataPath

  setDefaultStates:->

    {states} = @getOptions()
    if states.length < 3
      @options.states = ['default',-> warn "no state options passed" ]
