diff options
author | bptato <nincsnevem662@gmail.com> | 2023-12-18 20:24:21 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-18 20:34:30 +0100 |
commit | 240d999b5324cc76f6ad69afcdfc21ee3853c8bb (patch) | |
tree | 189fbe70b0edd0b2ed2d4b9d2a8470f0ef2bf7b1 /src/html | |
parent | a8022d1cbfe4c1a1a33ec7c8b1d2d5935d89e933 (diff) | |
download | chawan-240d999b5324cc76f6ad69afcdfc21ee3853c8bb.tar.gz |
html/dom: do not submit implicitly if there is a submit button
See e.g. the sr.ht issue tracker, now forever tainted by the tickets I accidentally submitted :P Chawan will gladly autosubmit without the user having written anything in the textbox just by writing some text in the title. The problem is that graphical web browsers typically have a "submit" keybinding (enter), and a "next field" keybinding (tab). The implicit submission mechanism was created with graphical browsers in mind; like w3m, Chawan only has an "ok" keybinding, which may or may not also mean "submit". With this solution, only forms that could not otherwise be submitted will autosubmit.
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/dom.nim | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index aa6a3d0e..c6441924 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -1601,6 +1601,14 @@ func `form=`*(element: FormAssociatedElement, form: HTMLFormElement) = of TAG_TEXTAREA: HTMLTextAreaElement(element).form = form else: assert false +func isSubmitButton*(element: Element): bool = + if element.tagType == TAG_BUTTON: + return element.attr("type") == "submit" + elif element.tagType == TAG_INPUT: + let element = HTMLInputElement(element) + return element.inputType in {INPUT_SUBMIT, INPUT_IMAGE} + return false + func canSubmitImplicitly*(form: HTMLFormElement): bool = const BlocksImplicitSubmission = { INPUT_TEXT, INPUT_SEARCH, INPUT_URL, INPUT_TEL, INPUT_EMAIL, INPUT_PASSWORD, @@ -1616,6 +1624,8 @@ func canSubmitImplicitly*(form: HTMLFormElement): bool = return false else: found = true + elif control.isSubmitButton(): + return false return true func qualifiedName*(element: Element): string = @@ -1940,14 +1950,6 @@ func isButton*(element: Element): bool = return element.inputType in {INPUT_SUBMIT, INPUT_BUTTON, INPUT_RESET, INPUT_IMAGE} return false -func isSubmitButton*(element: Element): bool = - if element.tagType == TAG_BUTTON: - return element.attr("type") == "submit" - elif element.tagType == TAG_INPUT: - let element = HTMLInputElement(element) - return element.inputType in {INPUT_SUBMIT, INPUT_IMAGE} - return false - func action*(element: Element): string = if element.isSubmitButton(): if element.attrb("formaction"): |