about summary refs log tree commit diff stats
path: root/src/xhr
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-07-02 14:32:03 +0200
committerbptato <nincsnevem662@gmail.com>2023-07-02 14:32:03 +0200
commit31cca81850bfe43771767dbffc2879a5061b84cd (patch)
treeb615e00e6c9e08cb5d787c69021b9edc1afaf29f /src/xhr
parent8430c0954798ee1632a933a9ca251be8302f6fb6 (diff)
downloadchawan-31cca81850bfe43771767dbffc2879a5061b84cd.tar.gz
FormData fixes
Diffstat (limited to 'src/xhr')
-rw-r--r--src/xhr/formdata.nim27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/xhr/formdata.nim b/src/xhr/formdata.nim
index b2656428..ad7a0529 100644
--- a/src/xhr/formdata.nim
+++ b/src/xhr/formdata.nim
@@ -26,8 +26,10 @@ proc newFormData*(form: HTMLFormElement = nil,
     this.entries = constructEntryList(form, submitter).get(@[])
   return ok(this)
 
-proc append[T: string|Blob](ctx: JSContext, this: FormData, name: string,
-    value: T, filename = opt(string)) {.jsfunc.} =
+#TODO filename should not be allowed for string entries
+# in other words, this should be an overloaded function, not just an or type
+proc append*[T: string|Blob](this: FormData, name: string, value: T,
+    filename = opt(string)) {.jsfunc.} =
   when T is Blob:
     let filename = if filename.isSome:
       filename.get
@@ -35,9 +37,18 @@ proc append[T: string|Blob](ctx: JSContext, this: FormData, name: string,
       WebFile(value).name
     else:
       "blob"
-    this.append(name, value, filename)
+    this.entries.add(FormDataEntry(
+      name: name,
+      isstr: false,
+      value: value,
+      filename: filename
+    ))
   else: # string
-    this.append(name, value, filename.get(""))
+    this.entries.add(FormDataEntry(
+      name: name,
+      isstr: true,
+      svalue: value
+    ))
 
 proc delete(this: FormData, name: string) {.jsfunc.} =
   for i in countdown(this.entries.high, 0):
@@ -53,10 +64,14 @@ proc get(ctx: JSContext, this: FormData, name: string): JSValue {.jsfunc.} =
         return toJS(ctx, entry.value)
   return JS_NULL
 
-proc getAll(this: FormData, name: string): seq[Blob] {.jsfunc.} =
+proc getAll(ctx: JSContext, this: FormData, name: string): seq[JSValue]
+    {.jsfunc.} =
   for entry in this.entries:
     if entry.name == name:
-      result.add(entry.value) # may be null
+      if entry.isstr:
+        result.add(toJS(ctx, entry.svalue))
+      else:
+        result.add(toJS(ctx, entry.value))
 
 proc add(list: var seq[FormDataEntry], entry: tuple[name, value: string]) =
   list.add(FormDataEntry(