Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form submission for <textarea> and <select> #7919

Merged
merged 1 commit into from Dec 30, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

form submission for <textarea> and <select>

small changes from code review

!child.get_disabled_state() becomes child.get_enabled_state()
  • Loading branch information
6112 committed Dec 30, 2015
commit 1f234af2ac646509dc83754404ce45d653be9df9
@@ -9,6 +9,7 @@ use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElemen
use dom::bindings::codegen::Bindings::HTMLFormElementBinding;
use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods;
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaElementMethods;
use dom::bindings::conversions::DerivedFrom;
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
@@ -293,39 +294,56 @@ impl HTMLFormElement {
let node = self.upcast::<Node>();
// FIXME(#3553): This is an incorrect way of getting controls owned
// by the form, but good enough until html5ever lands
node.traverse_preorder().filter_map(|child| {
let mut data_set = Vec::new();
for child in node.traverse_preorder() {
// Step 3.1: The field element is disabled.
match child.downcast::<Element>() {
Some(el) if !el.get_disabled_state() => (),
_ => return None,
_ => continue,
}

// Step 3.1: The field element has a datalist element ancestor.
if child.ancestors()
.any(|a| Root::downcast::<HTMLDataListElement>(a).is_some()) {
return None;
continue;
}
match child.type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(element)) => {
match element {
HTMLElementTypeId::HTMLInputElement => {
let input = child.downcast::<HTMLInputElement>().unwrap();
// Step 3.2-3.7
input.get_form_datum(submitter)
if let Some(datum) = input.get_form_datum(submitter) {
data_set.push(datum);
}
}
HTMLElementTypeId::HTMLButtonElement |
HTMLElementTypeId::HTMLSelectElement |
HTMLElementTypeId::HTMLObjectElement |
HTMLElementTypeId::HTMLTextAreaElement => {
HTMLElementTypeId::HTMLObjectElement => {
// Unimplemented
None
()
}
HTMLElementTypeId::HTMLSelectElement => {
let select = child.downcast::<HTMLSelectElement>().unwrap();
select.push_form_data(&mut data_set);
}
HTMLElementTypeId::HTMLTextAreaElement => {
let textarea = child.downcast::<HTMLTextAreaElement>().unwrap();
let name = textarea.Name();
if !name.is_empty() {
data_set.push(FormDatum {
ty: textarea.Type(),
name: name,
value: textarea.Value()
});
}
}
_ => None
_ => ()
}
}
_ => None
_ => ()
}
}).collect()
}
data_set
// TODO: Handle `dirnames` (needs directionality support)
// https://html.spec.whatwg.org/multipage/#the-directionality
}
@@ -14,7 +14,7 @@ use dom::document::Document;
use dom::element::{AttributeMutation, Element};
use dom::htmlelement::HTMLElement;
use dom::htmlfieldsetelement::HTMLFieldSetElement;
use dom::htmlformelement::{FormControl, HTMLFormElement};
use dom::htmlformelement::{FormControl, FormDatum, HTMLFormElement};
use dom::htmloptionelement::HTMLOptionElement;
use dom::node::{Node, UnbindContext, window_from_node};
use dom::nodelist::NodeList;
@@ -82,6 +82,23 @@ impl HTMLSelectElement {
}
}

pub fn push_form_data(&self, data_set: &mut Vec<FormDatum>) {
let node = self.upcast::<Node>();
if self.Name().is_empty() {
return;
}
for opt in node.traverse_preorder().filter_map(Root::downcast::<HTMLOptionElement>) {
let element = opt.upcast::<Element>();
if opt.Selected() && element.get_enabled_state() {
data_set.push(FormDatum {
ty: self.Type(),
name: self.Name(),
value: opt.Value()
});
}
}
}

// https://html.spec.whatwg.org/multipage/#concept-select-pick
pub fn pick_option(&self, picked: &HTMLOptionElement) {
if !self.Multiple() {

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.