about summary refs log tree commit diff stats
path: root/src/xhr
diff options
context:
space:
mode:
Diffstat (limited to 'src/xhr')
-rw-r--r--src/xhr/formdata.nim73
1 files changed, 35 insertions, 38 deletions
diff --git a/src/xhr/formdata.nim b/src/xhr/formdata.nim
index 77430509..87fa8dac 100644
--- a/src/xhr/formdata.nim
+++ b/src/xhr/formdata.nim
@@ -108,16 +108,16 @@ proc constructEntryList*(form: HTMLFormElement, submitter: Element = nil,
   if form.constructingentrylist:
     return
   form.constructingentrylist = true
-
-  var entrylist: seq[FormDataEntry]
+  var entrylist: seq[FormDataEntry] = @[]
   for field in form.controls:
     if field.findAncestor({TAG_DATALIST}) != nil or
         field.attrb(atDisabled) or
         field.isButton() and Element(field) != submitter:
       continue
-
-    if field.tagType == TAG_INPUT:
+    if field of HTMLInputElement:
       let field = HTMLInputElement(field)
+      if field.inputType in {INPUT_CHECKBOX, INPUT_RADIO} and not field.checked:
+        continue
       if field.inputType == INPUT_IMAGE:
         var name = field.attr(atName)
         if name != "":
@@ -125,56 +125,53 @@ proc constructEntryList*(form: HTMLFormElement, submitter: Element = nil,
         entrylist.add((name & 'x', $field.xcoord))
         entrylist.add((name & 'y', $field.ycoord))
         continue
-
     #TODO custom elements
-
     let name = field.attr(atName)
-
     if name == "":
       continue
-
-    if field.tagType == TAG_SELECT:
+    if field of HTMLSelectElement:
       let field = HTMLSelectElement(field)
       for option in field.options:
         if option.selected or option.isDisabled:
           entrylist.add((name, option.value))
-    elif field of HTMLInputElement and
-        HTMLInputElement(field).inputType in {INPUT_CHECKBOX, INPUT_RADIO}:
-      let v = field.attr(atValue)
-      let value = if v != "":
-        v
-      else:
-        "on"
-      entrylist.add((name, value))
-    elif field of HTMLInputElement and
-        HTMLInputElement(field).inputType == INPUT_FILE:
-      #TODO file
-      discard
-    elif field of HTMLInputElement and
-        HTMLInputElement(field).inputType == INPUT_HIDDEN and
-        name.equalsIgnoreCase("_charset_"):
-      let charset = if encoding != "":
-        encoding
+    elif field of HTMLInputElement:
+      let field = HTMLInputElement(field)
+      case field.inputType
+      of INPUT_CHECKBOX, INPUT_RADIO:
+        let v = field.attr(atValue)
+        let value = if v != "":
+          v
+        else:
+          "on"
+        entrylist.add((name, value))
+      of INPUT_FILE:
+        #TODO file
+        discard
+      of INPUT_HIDDEN:
+        if name.equalsIgnoreCase("_charset_"):
+          let charset = if encoding != "":
+            encoding
+          else:
+            "UTF-8"
+          entrylist.add((name, charset))
+        else:
+          entrylist.add((name, field.value))
       else:
-        "UTF-8"
-      entrylist.add((name, charset))
+        entrylist.add((name, field.value))
+    elif field of HTMLButtonElement:
+      entrylist.add((name, HTMLButtonElement(field).value))
+    elif field of HTMLTextAreaElement:
+      entrylist.add((name, HTMLTextAreaElement(field).value))
     else:
-      case field.tagType
-      of TAG_INPUT:
-        entrylist.add((name, HTMLInputElement(field).value))
-      of TAG_BUTTON:
-        entrylist.add((name, HTMLButtonElement(field).value))
-      of TAG_TEXTAREA:
-        entrylist.add((name, HTMLTextAreaElement(field).value))
-      else: assert false, "Tag type " & $field.tagType & " not accounted for in constructEntryList"
+      assert false, "Tag type " & $field.tagType &
+        " not accounted for in constructEntryList"
     if field of HTMLTextAreaElement or
         field of HTMLInputElement and
-        HTMLInputElement(field).inputType in {INPUT_TEXT, INPUT_SEARCH}:
+        HTMLInputElement(field).inputType in AutoDirInput:
       let dirname = field.attr(atDirname)
       if dirname != "":
         let dir = "ltr" #TODO bidi
         entrylist.add((dirname, dir))
-
   form.constructingentrylist = false
   return some(entrylist)
 
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420