mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
LibWeb: Implement activation behavior on input[type=reset]
This fixes WPT html/semantics/forms/resetting-a-form/reset-form.html. I added a test based on the WPT test, but simpler.
This commit is contained in:
parent
90bb8ed33e
commit
caf74e7ed6
Notes:
github-actions[bot]
2024-10-11 06:41:46 +00:00
Author: https://github.com/ferk6a 🔰 Commit: https://github.com/LadybirdBrowser/ladybird/commit/caf74e7ed69 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1716 Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 86 additions and 0 deletions
13
Tests/LibWeb/Text/expected/reset-input-element.txt
Normal file
13
Tests/LibWeb/Text/expected/reset-input-element.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
abc
|
||||
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
abc
|
||||
abc
|
||||
1
|
||||
2
|
||||
false
|
||||
true
|
||||
true
|
58
Tests/LibWeb/Text/input/reset-input-element.html
Normal file
58
Tests/LibWeb/Text/input/reset-input-element.html
Normal file
|
@ -0,0 +1,58 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="include.js"></script>
|
||||
<form name="fm1" style="display:none">
|
||||
<input value="abc" id="ipt1" />
|
||||
<input id="ipt2" />
|
||||
<input type="radio" id="rd1" checked="checked" />
|
||||
<input type="radio" id="rd2"/>
|
||||
<input type="checkbox" id="cb1" checked="checked" />
|
||||
<input type="checkbox" id="cb2" />
|
||||
<textarea id="ta">abc</textarea>
|
||||
<output id="opt">5</output>
|
||||
<select id="slt1">
|
||||
<option value="1">ITEM1</option>
|
||||
<option value="2">ITEM2</option>
|
||||
</select>
|
||||
<select id="slt2">
|
||||
<option value="1">ITEM1</option>
|
||||
<option value="2" selected>ITEM2</option>
|
||||
</select>
|
||||
<select id="slt3" multiple>
|
||||
<option value="1">ITEM1</option>
|
||||
<option value="2" selected>ITEM2</option>
|
||||
<option value="3" selected>ITEM3</option>
|
||||
</select>
|
||||
<button id="rst1" type="reset">Reset1</button>
|
||||
<input id="rst2" type="reset" value="Reset2" />
|
||||
</form>
|
||||
<script>
|
||||
test(() => {
|
||||
document.getElementById("ipt1").value = "123";
|
||||
document.getElementById("ipt2").value = "123";
|
||||
document.getElementById("rd1").checked = false;
|
||||
document.getElementById("rd2").checked = true;
|
||||
document.getElementById("cb1").checked = false;
|
||||
document.getElementById("cb2").checked = true;
|
||||
document.getElementById("ta").value = "123";
|
||||
document.getElementById("opt").textContent = "abc";
|
||||
document.getElementById("slt1").value = "2";
|
||||
document.getElementById("slt2").value = "1";
|
||||
document.getElementById("slt3").options[0].selected = true;
|
||||
document.getElementById("slt3").options[1].selected = false;
|
||||
document.getElementById("slt3").options[2].selected = false;
|
||||
document.getElementById("rst2").click();
|
||||
println(document.getElementById("ipt1").value);
|
||||
println(document.getElementById("ipt2").value);
|
||||
println(document.getElementById("rd1").checked);
|
||||
println(document.getElementById("rd2").checked);
|
||||
println(document.getElementById("cb1").checked);
|
||||
println(document.getElementById("cb2").checked);
|
||||
println(document.getElementById("ta").value);
|
||||
println(document.getElementById("opt").textContent);
|
||||
println(document.getElementById("slt1").value);
|
||||
println(document.getElementById("slt2").value);
|
||||
println(document.getElementById("slt3").options[0].selected);
|
||||
println(document.getElementById("slt3").options[1].selected);
|
||||
println(document.getElementById("slt3").options[2].selected);
|
||||
});
|
||||
</script>
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright (c) 2023-2024, Shannon Booth <shannon@serenityos.org>
|
||||
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
|
||||
* Copyright (c) 2024, Jelle Raaijmakers <jelle@gmta.nl>
|
||||
* Copyright (c) 2024, Fernando Kiotheka <fer@k6a.dev>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -406,6 +407,20 @@ WebIDL::ExceptionOr<void> HTMLInputElement::run_input_activation_behavior(DOM::E
|
|||
// 4. Submit the element's form owner from the element with userInvolvement set to event's user navigation involvement.
|
||||
TRY(form->submit_form(*this, { .user_involvement = user_navigation_involvement(event) }));
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/input.html#reset-button-state-(type=reset)
|
||||
else if (type_state() == TypeAttributeState::ResetButton) {
|
||||
// 1. If the element does not have a form owner, then return.
|
||||
auto* form = this->form();
|
||||
if (!form)
|
||||
return {};
|
||||
|
||||
// 2. If the element's node document is not fully active, then return.
|
||||
if (!document().is_fully_active())
|
||||
return {};
|
||||
|
||||
// 3. Reset the form owner from the element.
|
||||
form->reset_form();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue