pub struct Form { /* private fields */ }
Expand description
A HTML form. You can create a form with Form::new()
or Form::default()
(they are identical) and then use any of the provided methods to manipulate
it (for example adding child elements or attributes).
malvolio::prelude::Form::new()
.attribute(Method::Post)
.child(
Input::default()
.attribute(Type::Text)
.attribute(Placeholder::new("Username"))
.attribute(Name::new("username")),
)
.child(Br)
.child(
Input::new()
.attribute(Type::Email)
.attribute(Placeholder::new("Email"))
.attribute(Name::new("email")),
)
.child(Br)
.child(
Input::new()
.attribute(Type::Password)
.attribute(Placeholder::new("Password"))
.attribute(Name::new("password")),
)
.child(Br)
.child(
Input::new()
.attribute(Type::Password)
.attribute(Placeholder::new("Password confirmation"))
.attribute(Name::new("password_confirmation")),
)
.child(Br)
.child(
Input::new()
.attribute(Type::Submit)
.attribute(Value::new("Login!")),
);
Implementations
sourceimpl Form
impl Form
sourcepub fn children<I, C>(self, children: I) -> Self where
I: IntoIterator<Item = C>,
C: Into<BodyNode>,
pub fn children<I, C>(self, children: I) -> Self where
I: IntoIterator<Item = C>,
C: Into<BodyNode>,
Add a number of children to a form. This method accepts a single
argument which must implement IntoIterator
(so for example a
Vec
) where the item of the iterator implements Into<BodyNode>
(any of the types in this crate which you would expect to go in the body
of an HTML document should implement this).
Form::new().children(vec![1, 2, 3].into_iter().map(|item| {
Label::new(format!("Item number: {}", item))
}));
sourcepub fn child<C>(self, child: C) -> Self where
C: Into<BodyNode>,
pub fn child<C>(self, child: C) -> Self where
C: Into<BodyNode>,
Add a single child to a form. This method accepts a single item
implementing Into<BodyNode>
.
Form::new()
.child(Label::new("Some input"))
.child(Input::new().attribute(Name::new("some-input")));
sourcepub fn attribute<A>(self, attr: A) -> Self where
A: Into<FormAttr>,
pub fn attribute<A>(self, attr: A) -> Self where
A: Into<FormAttr>,
Add an attribute to the current form. This accepts any item implementing
Into<FormAttr>
(which is all the members of the FormAttr
enum).
Form::new()
.attribute(Method::Post)
.attribute(Action::new("/"));
sourcepub fn read_attribute(
&self,
attribute: &'static str
) -> Option<&Cow<'static, str>>
pub fn read_attribute(
&self,
attribute: &'static str
) -> Option<&Cow<'static, str>>
Read an attribute that has been set
sourcepub fn h1<C>(self, c: C) -> Self where
C: Into<H1>,
pub fn h1<C>(self, c: C) -> Self where
C: Into<H1>,
Attach a new H1
instance to this class. Note that this method only
allows you to provide text, and no additional attributes. If you
want to specify extra attributes, you should instead use the “child”
method (see the documentation of that method for more details).
Body::new().h1("Hello World!");
This is just a convenience wrapper, and is functionally equivalent to
calling the child
method (but somewhat more concise).
Body::new().child(H1::new("Hello World!"));
sourcepub fn h2<C>(self, c: C) -> Self where
C: Into<H2>,
pub fn h2<C>(self, c: C) -> Self where
C: Into<H2>,
Attach a new H2
instance to this class. Note that this method only
allows you to provide text, and no additional attributes. If you
want to specify extra attributes, you should instead use the “child”
method (see the documentation of that method for more details).
Body::new().h2("Hello World!");
This is just a convenience wrapper, and is functionally equivalent to
calling the child
method (but somewhat more concise).
Body::new().child(H2::new("Hello World!"));
sourcepub fn h3<C>(self, c: C) -> Self where
C: Into<H3>,
pub fn h3<C>(self, c: C) -> Self where
C: Into<H3>,
Attach a new H3
instance to this class. Note that this method only
allows you to provide text, and no additional attributes. If you
want to specify extra attributes, you should instead use the “child”
method (see the documentation of that method for more details).
Body::new().h3("Hello World!");
This is just a convenience wrapper, and is functionally equivalent to
calling the child
method (but somewhat more concise).
Body::new().child(H3::new("Hello World!"));
sourcepub fn h4<C>(self, c: C) -> Self where
C: Into<H4>,
pub fn h4<C>(self, c: C) -> Self where
C: Into<H4>,
Attach a new H4
instance to this class. Note that this method only
allows you to provide text, and no additional attributes. If you
want to specify extra attributes, you should instead use the “child”
method (see the documentation of that method for more details).
Body::new().h4("Hello World!");
This is just a convenience wrapper, and is functionally equivalent to
calling the child
method (but somewhat more concise).
Body::new().child(H4::new("Hello World!"));
sourcepub fn h5<C>(self, c: C) -> Self where
C: Into<H5>,
pub fn h5<C>(self, c: C) -> Self where
C: Into<H5>,
Attach a new H5
instance to this class. Note that this method only
allows you to provide text, and no additional attributes. If you
want to specify extra attributes, you should instead use the “child”
method (see the documentation of that method for more details).
Body::new().h5("Hello World!");
This is just a convenience wrapper, and is functionally equivalent to
calling the child
method (but somewhat more concise).
Body::new().child(H6::new("Hello World!"));
sourcepub fn h6<C>(self, c: C) -> Self where
C: Into<H6>,
pub fn h6<C>(self, c: C) -> Self where
C: Into<H6>,
Attach a new H6
instance to this class. Note that this method only
allows you to provide text, and no additional attributes. If you
want to specify extra attributes, you should instead use the “child”
method (see the documentation of that method for more details).
Body::new().h6("Hello World!");
This is just a convenience wrapper, and is functionally equivalent to
calling the child
method (but somewhat more concise).
Body::new().child(H6::new("Hello World!"));
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Form
impl Send for Form
impl Sync for Form
impl Unpin for Form
impl UnwindSafe for Form
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more