From 0ecbdc4627cd6a58b68f8b409e8ca6bb88d45c02 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 13 Feb 2024 22:37:16 +0000 Subject: [PATCH] LibWeb: Add support for form submission method 'dialog' --- .../Text/expected/form-method-dialog.txt | 2 ++ .../LibWeb/Text/input/form-method-dialog.html | 22 +++++++++++++++++ .../Libraries/LibWeb/HTML/HTMLFormElement.cpp | 24 +++++++++++++------ 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/form-method-dialog.txt create mode 100644 Tests/LibWeb/Text/input/form-method-dialog.html diff --git a/Tests/LibWeb/Text/expected/form-method-dialog.txt b/Tests/LibWeb/Text/expected/form-method-dialog.txt new file mode 100644 index 0000000000..0568a2a0cc --- /dev/null +++ b/Tests/LibWeb/Text/expected/form-method-dialog.txt @@ -0,0 +1,2 @@ + dialog.open before form submit: true +dialog.open after form submit: false diff --git a/Tests/LibWeb/Text/input/form-method-dialog.html b/Tests/LibWeb/Text/input/form-method-dialog.html new file mode 100644 index 0000000000..9e24c2221b --- /dev/null +++ b/Tests/LibWeb/Text/input/form-method-dialog.html @@ -0,0 +1,22 @@ + + + +
+ +
+
+ diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index acb117e87b..418b8aad0e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -179,17 +180,26 @@ WebIDL::ExceptionOr HTMLFormElement::submit_form(JS::NonnullGCPtr(); + if (!subject) + return {}; + + // 3. Let result be null. + Optional result; + // FIXME: 4. If submitter is an input element whose type attribute is in the Image Button state, then: // 1. Let (x, y) be the selected coordinate. // 2. Set result to the concatenation of x, ",", and y. - // FIXME: 5. Otherwise, if submitter has a value, then set result to that value. - // FIXME: 6. Close the dialog subject with result. - // FIXME: 7. Return. - dbgln("FIXME: Implement form submission with `dialog` action. Returning from form submission."); + // 5. Otherwise, if submitter has a value, then set result to that value. + result = submitter->get_attribute_value(AttributeNames::value); + + // 6. Close the dialog subject with result. + subject->close(move(result)); + + // 7. Return. return {}; }