diff options
author | bptato <nincsnevem662@gmail.com> | 2024-05-08 23:03:16 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-05-08 23:03:16 +0200 |
commit | 0ecdc3fcb376b62756c74c1e667002a5022863be (patch) | |
tree | 2bbde0814fb42f39813460241efdbacda57b5443 /src/html | |
parent | 264419bde7a73ba34095af65fd0f34ab88e7070a (diff) | |
download | chawan-0ecdc3fcb376b62756c74c1e667002a5022863be.tar.gz |
dom: simplify ButtonType
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/dom.nim | 14 | ||||
-rw-r--r-- | src/html/enums.nim | 4 |
2 files changed, 7 insertions, 11 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 3ee12f8d..5daba32e 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -2916,10 +2916,6 @@ proc reflectAttrs(element: Element; name: CAtom; value: string) = if name == n: element.val = element.document.toAtom(value) return - template reflect_str(element: Element; n: StaticAtom; val, fun: untyped) = - if name == n: - element.val = fun(value) - return template reflect_bool(element: Element; n: StaticAtom; val: untyped) = if name == n: element.val = true @@ -2953,19 +2949,17 @@ proc reflectAttrs(element: Element; name: CAtom; value: string) = of TAG_INPUT: let input = HTMLInputElement(element) input.reflect_str satValue, value - input.reflect_str satType, inputType, inputType input.reflect_bool satChecked, checked + if name == satType: + input.inputType = inputType(value) of TAG_OPTION: let option = HTMLOptionElement(element) option.reflect_bool satSelected, selected of TAG_BUTTON: let button = HTMLButtonElement(element) button.reflect_str satValue, value - button.reflect_str satType, ctype, (func(s: string): ButtonType = - case s.toLowerAscii() - of "submit": return BUTTON_SUBMIT - of "reset": return BUTTON_RESET - of "button": return BUTTON_BUTTON) + if name == satType: + button.ctype = parseEnumNoCase[ButtonType](value).get(btSubmit) of TAG_LINK: let link = HTMLLinkElement(element) if name == satRel: diff --git a/src/html/enums.nim b/src/html/enums.nim index 1cac0742..925e3b68 100644 --- a/src/html/enums.nim +++ b/src/html/enums.nim @@ -29,7 +29,9 @@ type itWeek = "week" ButtonType* = enum - BUTTON_SUBMIT, BUTTON_RESET, BUTTON_BUTTON + btSubmit = "submit" + btReset = "reset" + btButton = "button" NodeType* = enum ELEMENT_NODE = 1, |