about summary refs log tree commit diff stats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-21 01:26:34 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-21 01:26:34 +0100
commit8536956c866b3b34854bae84ed7ccb1172b1139a (patch)
treef48d0ff57d9f408b5a3ad7edad1b1316c7a105bc /src/html
parent075efc13165c5e5f24d1672c9830db53e41be1e6 (diff)
downloadchawan-8536956c866b3b34854bae84ed7ccb1172b1139a.tar.gz
dom: fix select default display
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index dd273b71..1a3b72d5 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -854,6 +854,15 @@ func attrigz*(element: Element, s: string): Option[int] =
   except ValueError:
     discard
 
+func attrigez*(element: Element, s: string): Option[int] =
+  let a = element.attr(s)
+  try:
+    let i = parseInt(a)
+    if i >= 0:
+      return some(i)
+  except ValueError:
+    discard
+
 func attrb*(element: Element, s: string): bool =
   if s in element.attrs:
     return true
@@ -863,12 +872,15 @@ func attrb*(element: Element, s: string): bool =
 func className(element: Element): string {.jsfget.} =
   element.attr("class")
 
-#TODO implement JS union types for ref object...
 func size*(element: HTMLInputElement): int {.jsfget.} =
   element.attrigz("size").get(20)
 
+#> For historical reasons, the default value of the size IDL attribute does
+#> not return the actual size used, which, in the absence of the size content
+#> attribute, is either 1 or 4 depending on the presence of the multiple
+#> attribute.
 func size*(element: HTMLSelectElement): int {.jsfget.} =
-  element.attrigz("size").get(20)
+  element.attrigz("size").get(0)
 
 func cols*(element: HTMLTextAreaElement): int {.jsfget.} =
   element.attrigz("cols").get(20)
@@ -1413,7 +1425,7 @@ proc resetElement*(element: Element) =
   of TAG_SELECT:
     let select = HTMLSelectElement(element)
     if not select.attrb("multiple"):
-      if select.size == 1:
+      if select.attrigez("size").get(1) == 1:
         var i = 0
         var firstOption: HTMLOptionElement
         for option in select.options: