From 14900f15118f79b841a17d4b0d817a60a551f2f3 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 30 Jul 2022 19:31:42 +0200 Subject: Add SupportedFormAssociatedElements --- src/html/dom.nim | 5 ++--- src/html/htmlparser.nim | 9 ++++----- src/html/tags.nim | 5 +++++ 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/html') diff --git a/src/html/dom.nim b/src/html/dom.nim index 109e5dc9..5dde41fa 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -497,9 +497,8 @@ func formmethod*(element: Element): FormMethod = of "dialog": FORM_METHOD_DIALOG else: FORM_METHOD_GET - # has form (TODO not only input should be included) - if element.tagType == TAG_INPUT: - let element = HTMLInputElement(element) + if element.tagType in SupportedFormAssociatedElements: + let element = FormAssociatedElement(element) if element.form != nil: if element.form.attrb("method"): return case element.form.attr("method").tolower() diff --git a/src/html/htmlparser.nim b/src/html/htmlparser.nim index e3c66f79..a8ea5458 100644 --- a/src/html/htmlparser.nim +++ b/src/html/htmlparser.nim @@ -198,14 +198,13 @@ func createElement(parser: HTML5Parser, token: Token, namespace: Namespace, inte if element.isResettable(): element.resetElement() - if element.tagType in FormAssociatedElements and parser.form != nil and + if element.tagType in SupportedFormAssociatedElements and parser.form != nil and not parser.openElements.hasElement(TAG_TEMPLATE) and (element.tagType notin ListedElements or not element.attrb("form")) and intendedParent.inSameTree(parser.form): - if element.tagType in {TAG_SELECT, TAG_INPUT}: #TODO implement the other ones too - let element = FormAssociatedElement(element) - element.setForm(parser.form) - element.parserInserted = true + let element = FormAssociatedElement(element) + element.setForm(parser.form) + element.parserInserted = true return element proc insert(location: AdjustedInsertionLocation, node: Node) = diff --git a/src/html/tags.nim b/src/html/tags.nim index d3bd7f6b..c009b2a5 100644 --- a/src/html/tags.nim +++ b/src/html/tags.nim @@ -104,6 +104,11 @@ const FormAssociatedElements* = { TAG_BUTTON, TAG_FIELDSET, TAG_INPUT, TAG_OBJECT, TAG_OUTPUT, TAG_SELECT, TAG_TEXTAREA, TAG_IMG } +#TODO support all the other ones +const SupportedFormAssociatedElements* = { + TAG_SELECT, TAG_INPUT +} + const ListedElements* = { TAG_BUTTON, TAG_FIELDSET, TAG_INPUT, TAG_OBJECT, TAG_OUTPUT, TAG_SELECT, TAG_TEXTAREA } -- cgit 1.4.1-2-gfad0