From 5bca2c6e71f86558625b406c6380abba558d94fc Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 19 Jan 2024 20:42:10 +0100 Subject: Fix form action when submitter has a "form" attr * Unify form variable for all form-associated elements * Fix broken form association logic in resetFormOwner * Use form action for all form-associated submitters * Remove unused getElementsByTag + de-extern some functions --- src/html/dom.nim | 43 ++++++++++++++++++++++++++----------------- src/server/buffer.nim | 7 ++++--- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/html/dom.nim b/src/html/dom.nim index 1a1913b1..ac709ba1 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -214,10 +214,10 @@ type dataset {.jsget.}: DOMStringMap FormAssociatedElement* = ref object of HTMLElement + form: HTMLFormElement parserInserted*: bool HTMLInputElement* = ref object of FormAssociatedElement - form* {.jsget.}: HTMLFormElement inputType*: InputType value* {.jsget.}: string checked* {.jsget.}: bool @@ -229,7 +229,6 @@ type relList {.jsget.}: DOMTokenList HTMLSelectElement* = ref object of FormAssociatedElement - form* {.jsget.}: HTMLFormElement HTMLSpanElement* = ref object of HTMLElement @@ -293,12 +292,10 @@ type relList {.jsget.}: DOMTokenList HTMLButtonElement* = ref object of FormAssociatedElement - form* {.jsget.}: HTMLFormElement ctype*: ButtonType value* {.jsget, jsset.}: string HTMLTextAreaElement* = ref object of FormAssociatedElement - form* {.jsget.}: HTMLFormElement value* {.jsget.}: string HTMLLabelElement* = ref object of HTMLElement @@ -1692,7 +1689,7 @@ func rootNode*(node: Node): Node = if node.root == nil: return node return node.root -func isConnected*(node: Node): bool {.jsfget.} = +func isConnected(node: Node): bool {.jsfget.} = return node.rootNode.nodeType == DOCUMENT_NODE #TODO shadow root func inSameTree*(a, b: Node): bool = @@ -1732,17 +1729,13 @@ func findAncestor*(node: Node, tagTypes: set[TagType]): Element = return element return nil -func getElementById*(node: Node, id: string): Element {.jsfunc.} = +func getElementById(node: Node, id: string): Element {.jsfunc.} = if id.len == 0: return nil for child in node.elements: if child.id == id: return child -func getElementsByTag*(node: Node, tag: TagType): seq[Element] = - for element in node.elements(tag): - result.add(element) - func getElementsByTagName0(root: Node, tagName: string): HTMLCollection = if tagName == "*": return newCollection[HTMLCollection](root, func(node: Node): bool = node.isElement, true, false) @@ -1989,8 +1982,8 @@ func action*(element: Element): string = if element.isSubmitButton(): if element.attrb("formaction"): return element.attr("formaction") - if element.tagType == TAG_INPUT: - let element = HTMLInputElement(element) + if element of FormAssociatedElement: + let element = FormAssociatedElement(element) if element.form != nil: if element.form.attrb("action"): return element.form.attr("action") @@ -2151,6 +2144,22 @@ proc setRelList(link: HTMLLinkElement, s: string) {.jsfset: "relList".} = proc setRelList(form: HTMLFormElement, s: string) {.jsfset: "relList".} = form.attr("rel", s) +# +func jsForm(this: HTMLInputElement): HTMLFormElement {.jsfget: "form".} = + return this.form + +#