Add click handler for <input type=submit>

This commit is contained in:
Manish Goregaokar 2014-10-11 19:28:03 +05:30
parent 05134e6d1f
commit 749e2394c5
2 changed files with 20 additions and 2 deletions

View file

@ -14,11 +14,11 @@ use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable, ResultRootable};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::attr::{AttrHelpers};
use dom::document::{Document, DocumentHelpers};
use dom::element::{AttributeHandlers, Element, HTMLInputElementTypeId };
use dom::element::{AttributeHandlers, Element, HTMLInputElementTypeId};
use dom::event::Event;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::htmlformelement::{FormOwner, HTMLFormElement};
use dom::htmlformelement::{InputElement, FormOwner, HTMLFormElement, HTMLFormElementHelpers};
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
@ -420,6 +420,11 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> {
match self.input_type.get() {
InputCheckbox => self.SetChecked(!self.checked.get()),
InputRadio => self.SetChecked(true),
InputButton(Some(DEFAULT_SUBMIT_VALUE)) => {
self.form_owner().map(|o| {
o.submit(false, InputElement(self.clone()))
});
}
_ => {}
}
}

View file

@ -0,0 +1,13 @@
<html>
<head></head>
<body>
<!-- Run with nc -l 8000 -->
<form action="http://localhost:8000" method=get id="foo">
<input name=bar type=checkbox checked>
<input name=baz value="baz1" type=radio checked>
<input name=baz value="baz2" type=radio>
<input type=text name=bye value="hi!">
<input type=submit>
</form>
</body>
</html>