     Form.events
       'click button.cancel': (e, template) ->
         e.preventDefault()
-        console.debug 'onCancel', arguments, @
         formArgs.onCancel?(template)
         formTemplate = getTemplate(template)
         formTemplate.settings.onCancel?()

      onSuccess: (operation, result) ->
        args = arguments
        template = getTemplate(@template)
        console.debug 'onSuccess', args, @
        AutoForm.resetForm(name)
        onSuccess = formArgs.onSuccess ? formArgs.hooks?.onSuccess
        result = onSuccess?.apply(@, args)
        callback = => template.settings.onSuccess?.apply(@, args)
        deferCallback(result, callback)

      onError: (operation, error) ->
        template = getTemplate(@template)

    # AUXILIARY
    ################################################################################################

    Form.setUpDocs = (template) ->
      template = getTemplate(template)
      data = template.data
      template.docs = Form.parseDocs(template)
      data.doc = Form.getValues(template)
      template.origDoc = Setter.clone(data.doc)

    Form.updateDocs = (template) ->
      template = getTemplate(template)
      data = template.data
      docs = _.map template.docs, (doc) -> Form.getCollection().findOne(doc._id)
      template.docs = docs
      data.doc = Form.getValues(template)
      if data.docs?
        data.docs = docs

    Form.parseDocs = (template) ->
      template = getTemplate(template)
      data = template.data
