use yew::{function_component, html, virtual_dom::AttrValue, Callback, InputEvent, Properties}; use yew_form::{Form, Model}; #[derive(Properties, PartialEq)] pub struct Props { pub label: AttrValue, pub field_name: String, pub form: Form, #[prop_or(false)] pub required: bool, #[prop_or(String::from("text"))] pub input_type: String, // If not present, will default to field_name #[prop_or(None)] pub autocomplete: Option, #[prop_or_else(Callback::noop)] pub oninput: Callback, } #[function_component(Field)] pub fn field(props: &Props) -> Html { html! {
form={&props.form} field_name={props.field_name.clone()} input_type={props.input_type.clone()} class="form-control" class_invalid="is-invalid has-error" class_valid="has-success" autocomplete={props.autocomplete.clone().unwrap_or(props.field_name.clone())} oninput={&props.oninput} />
{&props.form.field_message(&props.field_name)}
} }