     ################################################################################################
 
     updateDataDocs = (template) ->
+      template = getTemplate(template)
       data = template.data ?= {}
       doc = Form.getValues(template)
+      # Avoid setting original data.doc to undefined value.
       if doc? then data.doc = doc
+      # NOTE: Reactive doc is undefined until doc is loaded, unlike getDoc() which may return
+      # empty docs. This is to aid templates in deciding when to use the reactive doc.
+      template.reactiveDoc?.set(doc)
       docs = template.docs.get()
       if data.docs? then data.docs = _.keys(docs)
 

      return unless docIds.length > 0
      collection = Form.getCollection()
      singularName = Form.getSingularName()
      _updateDocs = ->
        Form.updateDocs(template)
        # NOTE: Reactive doc is undefined until doc is loaded, unlike getDoc() which may return
        # empty docs. This is to aid templates in deciding when to use the reactive doc.
        template.reactiveDoc.set(template.data?.doc)
      updateDocs = _.debounce _updateDocs, 500
      # Check if the doc has changed and ensure the current form is not submitting to prevent
      # self-detection.
      template.autorun ->


    Form.getDocs = (template) ->
      # For undefined docs which have not yet been resolved, return an empty doc.
      _.map getTemplate(template).docs.get(), (value, key) -> value ? {_id: key}

    Form.hasDoc = (template) -> Form.getDocs(template).length > 0
    
