     console.log(result)
     single_defer.resolve()
   )
-  group_encryption(form, values, (result) ->
-    #console.log(result)
-    group_defer.resolve()
-  )
-  $.when(single_defer, group_defer).done(() -> # Spat defers to param list with apply
+  $.when(single_defer).done(()->
+    group_encryption(form, values, (result) ->
+      console.log(result)
+      group_defer.resolve()
+    )
+  )
+  $.when(single_defer, group_defer).done(() ->
+    #console.log values
+    #reinsert_values values
     #form.submit()
   )
 

    return placeholder
  else
    return name
wipe_source_fields = (data, encryption_source_names) ->
  for element in data
    if contains(element.name, encryption_source_names)
      element.value = ""

#write_target = (buffer )->
#  target = $("*[data-encrypt-target]")
#  #console.log(target[0])
#  if target[0]
#    encrypt(buffer, (result_string) ->
#      target[0].value = result_string.toString()
#    )
#  else
#    console.error("No target defined")




$(document).ready(ready)
$(document).on('page:load', ready)

  buffer = collect_sources(elements)
  encryption_source_names = find_names_for(form, elements)
  wipe_source_fields(values, encryption_source_names)
  write_target(buffer, values)
  callback(values)

collect_sources = (elements)->
  buffer = ""
