diff options
author | bptato <nincsnevem662@gmail.com> | 2024-01-19 20:42:10 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-01-19 20:49:35 +0100 |
commit | 5bca2c6e71f86558625b406c6380abba558d94fc (patch) | |
tree | 527d9cad7105ceac2acf11d0553787dd4bf879ce /src/html | |
parent | 5d3302287ff98c437c5c7592b32e1583e4b7362b (diff) | |
download | chawan-5bca2c6e71f86558625b406c6380abba558d94fc.tar.gz |
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
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/dom.nim | 43 |
1 files changed, 26 insertions, 17 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) +# <input> +func jsForm(this: HTMLInputElement): HTMLFormElement {.jsfget: "form".} = + return this.form + +# <select> +func jsForm(this: HTMLSelectElement): HTMLFormElement {.jsfget: "form".} = + return this.form + +# <button> +func jsForm(this: HTMLButtonElement): HTMLFormElement {.jsfget: "form".} = + return this.form + +# <textarea> +func jsForm(this: HTMLTextAreaElement): HTMLFormElement {.jsfget: "form".} = + return this.form + func newText(document: Document, data: string): Text = return Text( nodeType: TEXT_NODE, @@ -2750,11 +2759,11 @@ proc resetFormOwner(element: FormAssociatedElement) = if not element.attrb("form") and lastForm == element.form: return element.form = nil - if element.tagType in ListedElements and element.attrb("form") and element.isConnected: - let form = element.attr("form") - for desc in element.elements(TAG_FORM): - if desc.id == form: - element.setForm(HTMLFormElement(desc)) + if element.tagType in ListedElements and element.attrb("form") and + element.isConnected: + let form = element.document.getElementById(element.attr("form")) + if form of HTMLFormElement: + element.setForm(HTMLFormElement(form)) proc insertionSteps(insertedNode: Node) = if insertedNode.nodeType == ELEMENT_NODE: |