mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +00:00
LibWeb: Add support for form submission method 'dialog'
This commit is contained in:
parent
151cd11b5b
commit
0ecbdc4627
3 changed files with 41 additions and 7 deletions
2
Tests/LibWeb/Text/expected/form-method-dialog.txt
Normal file
2
Tests/LibWeb/Text/expected/form-method-dialog.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
dialog.open before form submit: true
|
||||||
|
dialog.open after form submit: false
|
22
Tests/LibWeb/Text/input/form-method-dialog.html
Normal file
22
Tests/LibWeb/Text/input/form-method-dialog.html
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<style>
|
||||||
|
#test-dialog {
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script src="./include.js"></script>
|
||||||
|
<dialog id="test-dialog" open>
|
||||||
|
<form method="dialog">
|
||||||
|
<button id="submit-button">Submit</button>
|
||||||
|
</form>
|
||||||
|
</dialog>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const dialog = document.getElementById("test-dialog");
|
||||||
|
const submitter = document.getElementById("submit-button");
|
||||||
|
const submitterRect = submitter.getBoundingClientRect();
|
||||||
|
const form = document.forms[0];
|
||||||
|
println(`dialog.open before form submit: ${dialog.open}`);
|
||||||
|
form.submit();
|
||||||
|
println(`dialog.open after form submit: ${dialog.open}`);
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -17,6 +17,7 @@
|
||||||
#include <LibWeb/HTML/EventNames.h>
|
#include <LibWeb/HTML/EventNames.h>
|
||||||
#include <LibWeb/HTML/FormControlInfrastructure.h>
|
#include <LibWeb/HTML/FormControlInfrastructure.h>
|
||||||
#include <LibWeb/HTML/HTMLButtonElement.h>
|
#include <LibWeb/HTML/HTMLButtonElement.h>
|
||||||
|
#include <LibWeb/HTML/HTMLDialogElement.h>
|
||||||
#include <LibWeb/HTML/HTMLFieldSetElement.h>
|
#include <LibWeb/HTML/HTMLFieldSetElement.h>
|
||||||
#include <LibWeb/HTML/HTMLFormElement.h>
|
#include <LibWeb/HTML/HTMLFormElement.h>
|
||||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||||
|
@ -179,17 +180,26 @@ WebIDL::ExceptionOr<void> HTMLFormElement::submit_form(JS::NonnullGCPtr<HTMLElem
|
||||||
|
|
||||||
// 11. If method is dialog, then:
|
// 11. If method is dialog, then:
|
||||||
if (method == MethodAttributeState::Dialog) {
|
if (method == MethodAttributeState::Dialog) {
|
||||||
// FIXME: 1. If form does not have an ancestor dialog element, then return.
|
// 1. If form does not have an ancestor dialog element, then return.
|
||||||
// FIXME: 2. Let subject be form's nearest ancestor dialog element.
|
// 2. Let subject be form's nearest ancestor dialog element.
|
||||||
// FIXME: 3. Let result be null.
|
auto* subject = first_ancestor_of_type<HTMLDialogElement>();
|
||||||
|
if (!subject)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// 3. Let result be null.
|
||||||
|
Optional<String> result;
|
||||||
|
|
||||||
// FIXME: 4. If submitter is an input element whose type attribute is in the Image Button state, then:
|
// 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.
|
// 1. Let (x, y) be the selected coordinate.
|
||||||
// 2. Set result to the concatenation of x, ",", and y.
|
// 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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue