mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
LibWeb: Add output element value
This commit is contained in:
parent
f8509e2183
commit
fef7571931
5 changed files with 84 additions and 4 deletions
2
Tests/LibWeb/Text/expected/output-value.txt
Normal file
2
Tests/LibWeb/Text/expected/output-value.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
1. "PASS"
|
||||||
|
2. "PASS"
|
27
Tests/LibWeb/Text/input/output-value.html
Normal file
27
Tests/LibWeb/Text/input/output-value.html
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<script src="./include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
let testCounter = 1;
|
||||||
|
function testPart(part) {
|
||||||
|
println(`${testCounter++}. ${JSON.stringify(part())}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Set output element value
|
||||||
|
testPart(() => {
|
||||||
|
const output = document.createElement('output');
|
||||||
|
output.value = 'PASS';
|
||||||
|
return output.textContent;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Set output element default value and reset
|
||||||
|
testPart(() => {
|
||||||
|
const form = document.createElement('form');
|
||||||
|
const output = document.createElement('output');
|
||||||
|
output.defaultValue = 'PASS';
|
||||||
|
output.value = 'FAIL';
|
||||||
|
form.appendChild(output);
|
||||||
|
form.reset();
|
||||||
|
return output.textContent;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -24,12 +24,55 @@ void HTMLOutputElement::initialize(JS::Realm& realm)
|
||||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLOutputElementPrototype>(realm, "HTMLOutputElement"_fly_string));
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLOutputElementPrototype>(realm, "HTMLOutputElement"_fly_string));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-output-defaultvalue
|
||||||
|
String HTMLOutputElement::default_value() const
|
||||||
|
{
|
||||||
|
// 1. If this element's default value override is non-null, then return it.
|
||||||
|
if (m_default_value_override.has_value())
|
||||||
|
return *m_default_value_override;
|
||||||
|
|
||||||
|
// 2. Return this element's descendant text content.
|
||||||
|
return descendant_text_content();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-output-defaultvalue
|
||||||
|
void HTMLOutputElement::set_default_value(String const& default_value)
|
||||||
|
{
|
||||||
|
// 1. If this's default value override is null, then string replace all with the given value within this and return.
|
||||||
|
if (!m_default_value_override.has_value()) {
|
||||||
|
string_replace_all(default_value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Set this's default value override to the given value.
|
||||||
|
m_default_value_override = default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-output-value
|
||||||
|
String HTMLOutputElement::value() const
|
||||||
|
{
|
||||||
|
// The value getter steps are to return this's descendant text content.
|
||||||
|
return descendant_text_content();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-output-value
|
||||||
|
void HTMLOutputElement::set_value(String const& value)
|
||||||
|
{
|
||||||
|
// 1. Set this's default value override to its default value.
|
||||||
|
m_default_value_override = default_value();
|
||||||
|
|
||||||
|
// 2. String replace all with the given value within this.
|
||||||
|
string_replace_all(value);
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/form-elements.html#the-output-element:concept-form-reset-control
|
// https://html.spec.whatwg.org/multipage/form-elements.html#the-output-element:concept-form-reset-control
|
||||||
void HTMLOutputElement::reset_algorithm()
|
void HTMLOutputElement::reset_algorithm()
|
||||||
{
|
{
|
||||||
// 1. FIXME: String replace all with this element's default value within this element.
|
// 1. String replace all with this element's default value within this element.
|
||||||
|
string_replace_all(default_value());
|
||||||
|
|
||||||
// 2. FIXME: Set this element's default value override to null.
|
// 2. Set this element's default value override to null.
|
||||||
|
m_default_value_override = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,12 @@ public:
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String default_value() const;
|
||||||
|
void set_default_value(String const&);
|
||||||
|
|
||||||
|
String value() const override;
|
||||||
|
void set_value(String const&);
|
||||||
|
|
||||||
// ^FormAssociatedElement
|
// ^FormAssociatedElement
|
||||||
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
|
// https://html.spec.whatwg.org/multipage/forms.html#category-listed
|
||||||
virtual bool is_listed() const override { return true; }
|
virtual bool is_listed() const override { return true; }
|
||||||
|
@ -52,6 +58,8 @@ private:
|
||||||
HTMLOutputElement(DOM::Document&, DOM::QualifiedName);
|
HTMLOutputElement(DOM::Document&, DOM::QualifiedName);
|
||||||
|
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
||||||
|
Optional<String> m_default_value_override {};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ interface HTMLOutputElement : HTMLElement {
|
||||||
[CEReactions, Reflect] attribute DOMString name;
|
[CEReactions, Reflect] attribute DOMString name;
|
||||||
|
|
||||||
readonly attribute DOMString type;
|
readonly attribute DOMString type;
|
||||||
// FIXME: [CEReactions] attribute DOMString defaultValue;
|
[CEReactions] attribute DOMString defaultValue;
|
||||||
// FIXME: [CEReactions] attribute DOMString value;
|
[CEReactions] attribute DOMString value;
|
||||||
|
|
||||||
// FIXME: readonly attribute boolean willValidate;
|
// FIXME: readonly attribute boolean willValidate;
|
||||||
// FIXME: readonly attribute ValidityState validity;
|
// FIXME: readonly attribute ValidityState validity;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue