about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/css/cascade.nim1
-rw-r--r--src/html/chadombuilder.nim1
-rw-r--r--src/html/dom.nim3
-rw-r--r--src/html/enums.nim44
-rw-r--r--src/server/buffer.nim3
-rw-r--r--src/version.nim2
-rw-r--r--src/xhr/formdata.nim1
7 files changed, 51 insertions, 4 deletions
diff --git a/src/css/cascade.nim b/src/css/cascade.nim
index 6c8ccbb7..288d6a89 100644
--- a/src/css/cascade.nim
+++ b/src/css/cascade.nim
@@ -11,6 +11,7 @@ import css/sheet
 import css/stylednode
 import css/values
 import html/dom
+import html/enums
 import layout/layoutunit
 import types/color
 import types/opt
diff --git a/src/html/chadombuilder.nim b/src/html/chadombuilder.nim
index 23273747..f070fe8f 100644
--- a/src/html/chadombuilder.nim
+++ b/src/html/chadombuilder.nim
@@ -3,6 +3,7 @@ import options
 import streams
 
 import html/dom
+import html/enums
 import js/error
 import js/fromjs
 import js/javascript
diff --git a/src/html/dom.nim b/src/html/dom.nim
index acc8ae30..4fcc6c51 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -11,6 +11,7 @@ import css/cssparser
 import css/sheet
 import css/values
 import display/window
+import html/enums
 import html/event
 import img/bitmap
 import img/painter
@@ -2183,8 +2184,6 @@ proc reflectAttrs(element: Element, name, value: string) =
     let input = HTMLInputElement(element)
     input.reflect_str "value", value
     input.reflect_str "type", inputType, inputType
-    if input.inputType == INPUT_UNKNOWN:
-      input.inputType = INPUT_TEXT
     input.reflect_bool "checked", checked
   of TAG_OPTION:
     let option = HTMLOptionElement(element)
diff --git a/src/html/enums.nim b/src/html/enums.nim
new file mode 100644
index 00000000..54de6af6
--- /dev/null
+++ b/src/html/enums.nim
@@ -0,0 +1,44 @@
+import strutils
+import tables
+
+import chame/tags
+
+type
+  InputType* = enum
+    INPUT_TEXT, INPUT_BUTTON, INPUT_CHECKBOX, INPUT_COLOR, INPUT_DATE,
+    INPUT_DATETIME_LOCAL, INPUT_EMAIL, INPUT_FILE, INPUT_HIDDEN, INPUT_IMAGE,
+    INPUT_MONTH, INPUT_NUMBER, INPUT_PASSWORD, INPUT_RADIO, INPUT_RANGE,
+    INPUT_RESET, INPUT_SEARCH, INPUT_SUBMIT, INPUT_TEL, INPUT_TIME, INPUT_URL,
+    INPUT_WEEK
+
+  ButtonType* = enum
+    BUTTON_SUBMIT, BUTTON_RESET, BUTTON_BUTTON
+
+#TODO support all the other ones
+const SupportedFormAssociatedElements* = {
+  TAG_BUTTON, TAG_INPUT, TAG_SELECT, TAG_TEXTAREA
+}
+
+const InputTypeWithSize* = {
+  INPUT_SEARCH, INPUT_TEXT, INPUT_EMAIL, INPUT_PASSWORD, INPUT_URL, INPUT_TEL
+}
+
+const AutocapitalizeInheritingElements* = {
+  TAG_BUTTON, TAG_FIELDSET, TAG_INPUT, TAG_OUTPUT, TAG_SELECT, TAG_TEXTAREA
+}
+
+const LabelableElements* = {
+  # input only if type not hidden
+  TAG_BUTTON, TAG_INPUT, TAG_METER, TAG_OUTPUT, TAG_PROGRESS, TAG_SELECT, TAG_TEXTAREA
+}
+
+func getInputTypeMap(): Table[string, InputType] =
+  for i in InputType:
+    let enumname = $InputType(i)
+    let tagname = enumname.split('_')[1..^1].join("_").toLowerAscii()
+    result[tagname] = InputType(i)
+
+const inputTypeMap = getInputTypeMap()
+
+func inputType*(s: string): InputType =
+  return inputTypeMap.getOrDefault(s.toLowerAscii())
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index fb87c719..70df60ef 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -20,6 +20,7 @@ import css/values
 import display/window
 import html/chadombuilder
 import html/dom
+import html/enums
 import html/env
 import html/event
 import img/png
@@ -44,9 +45,9 @@ import types/cell
 import types/color
 import types/cookie
 import types/formdata
+import types/opt
 import types/referer
 import types/url
-import types/opt
 import utils/twtstr
 import xhr/formdata as formdata_impl
 
diff --git a/src/version.nim b/src/version.nim
index 5e1976db..90142ab2 100644
--- a/src/version.nim
+++ b/src/version.nim
@@ -28,4 +28,4 @@ tryImport chame/version, "chame"
 
 static:
   checkVersion("chakasu", 0, 2, 0)
-  checkVersion("chame", 0, 10, 1)
+  checkVersion("chame", 0, 11, 0)
diff --git a/src/xhr/formdata.nim b/src/xhr/formdata.nim
index 57af59bf..84c13402 100644
--- a/src/xhr/formdata.nim
+++ b/src/xhr/formdata.nim
@@ -1,4 +1,5 @@
 import html/dom
+import html/enums
 import js/domexception
 import js/javascript
 import js/tojs