     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()
   )
 

  defers = []
  encrypt_requested_fields(values, names_to_encrypt, defers)
  $.when.apply($, defers).done(() -> # Spat defers to param list with apply
    reinsert_values values
    callback(values)
  )


    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, data)->
  target_name = $("*[data-encrypt-target]").attr("name")
  if target_name[0]
    encrypt(buffer, (result_string) ->
      data[0].value =result_string.toString()
      #data.push {name: target_name, value: result_string.toString()}
      console.log data
    )
  else
    console.error("No target defined")

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