Edit Component
Adding Form RS to your project is simple:
-
Make sure your project is set up with Yew. Follow their Getting Started Guide for setup instructions.
-
Add the Form RS component to your dependencies by including it in your Cargo.toml file:
cargo add form-rs --features=yew
-
Import the form components into your Yew component and start using them in your app.
use form_rs::yew::{Form, Control, FormLabel, Helper, Field};
use form_rs::{Method, ValidationState};
use yew::prelude::*;
#[function_component(LoginForm)]
pub fn login_form() -> Html {
let email = use_state(String::new);
let email_valid = use_state(|| true);
html! {
<Form method={Method::Post}>
<Field
id="email"
label="Email"
r#type="email"
placeholder="ferris@opensass.org"
helper_text="Enter a valid email."
required={true}
full_width={true}
handle={email.clone()}
valid_handle={email_valid.clone()}
validate_function={Callback::from(|v: String| v.contains('@') && v.contains('.'))}
/>
</Form>
}
}
use form_rs::yew::{Form, Field};
use form_rs::{ValidationState};
use yew::prelude::*;
#[function_component(AriaForm)]
pub fn aria_form() -> Html {
let val = use_state(String::new);
let valid = use_state(|| true);
html! {
<Form>
<Field
id="username"
label="Username"
r#type="text"
helper_text="3-20 characters."
validation_state={ValidationState::Invalid("Too short".into())}
handle={val.clone()}
valid_handle={valid.clone()}
validate_function={Callback::from(|v: String| v.len() >= 3)}
/>
</Form>
}
}
use form_rs::yew::{Form, Group, ControlLabel};
use form_rs::LabelPlacement;
use yew::prelude::*;
#[function_component(CheckboxGroup)]
pub fn checkbox_group() -> Html {
html! {
<Form>
<Group>
<ControlLabel
label="Email notifications"
label_placement={LabelPlacement::End}
control={html! { <input type="checkbox" /> }}
/>
<ControlLabel
label="SMS notifications"
label_placement={LabelPlacement::End}
control={html! { <input type="checkbox" /> }}
/>
</Group>
</Form>
}
}
| Property | Type | Description | Default |
method | Method | HTTP submission method. | Method::Get |
action | &'static str | Form submission URL. | "" |
enc_type | EncType | Encoding type for submission. | EncType::UrlEncoded |
novalidate | bool | Bypass browser native validation. | false |
autocomplete | &'static str | autocomplete attribute. | "off" |
on_submit | Option<Callback<SubmitEvent>> | Submit handler. | None |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
aria_label | &'static str | Accessible label. | "" |
| Property | Type | Description | Default |
disabled | bool | Disables the control. | false |
error | bool | Shows error state. | false |
focused | bool | Shows focused state. | false |
full_width | bool | Expands to full width. | false |
required | bool | Marks as required. | false |
variant | Variant | Visual style (Outlined, Filled, Standard). | Outlined |
color | Color | Accent color. | Primary |
size | Size | Input size (Small, Medium). | Medium |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
id | &'static str | Input id and label for. Required. | - |
label | &'static str | Label text. | "" |
r#type | &'static str | Input type (text, email, passwordβ¦). | "text" |
placeholder | &'static str | Placeholder text. | "" |
helper_text | &'static str | Helper message below the input. | "" |
validation_state | ValidationState | External validation result. | None |
required | bool | HTML required attribute. | false |
disabled | bool | Disables the input. | false |
full_width | bool | Expands to full width. | true |
variant | Variant | Visual style. | Outlined |
color | Color | Accent color. | Primary |
size | Size | Input size. | Medium |
pattern | &'static str | Regex pattern for native validation. | ".*" |
maxlength | Option<usize> | Maximum character count. | None |
minlength | Option<usize> | Minimum character count. | None |
handle | UseStateHandle<String> | Controlled value handle. Required. | - |
valid_handle | UseStateHandle<bool> | Validity state handle. Required. | - |
validate_function | Callback<String, bool> | Custom validator. Required. | - |
| Property | Type | Description | Default |
html_for | &'static str | for attribute linking to input id. | "" |
error | bool | Shows error color. | false |
focused | bool | Shows focused color. | false |
required | bool | Appends required asterisk. | false |
disabled | bool | Renders in disabled style. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
error | bool | Renders in error color. | false |
valid | bool | Renders in success color. | false |
disabled | bool | Renders in disabled style. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
row | bool | Lays children horizontally. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
label | Html | Label text or element. Required. | - |
label_placement | LabelPlacement | End, Start, Top, or Bottom. | End |
disabled | bool | Renders in disabled style. | false |
required | bool | Appends required asterisk. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
Field is a convenience composition of Control + FormLabel + Input + Helper. Use it for the common case.
- Use
Control + FormLabel + Helper manually when you need full layout control.
- Set
validation_state={ValidationState::Invalid("message".into())} to show server-side errors.
- All components are WCAG 2.2 AA compliant,
aria-describedby, aria-required, and aria-invalid are wired automatically.
You can import Form RS directly into your project to customize and modify it using the opensass cli:
os add form-rs yew
Edit Component
Adding Form RS to your project is simple:
-
Make sure your project is set up with Dioxus. Follow their Getting Started Guide for setup instructions.
-
Add the Form RS component to your dependencies by including it in your Cargo.toml file:
cargo add form-rs --features=dio
-
Import the form components into your Dioxus component and start using them in your app.
use form_rs::dioxus::{Form, Field};
use form_rs::{Method, ValidationState};
use dioxus::prelude::*;
fn validate_email(v: String) -> bool {
!v.is_empty() && v.contains('@') && v.contains('.')
}
#[component]
fn LoginForm() -> Element {
let email = use_signal(String::new);
let email_valid = use_signal(|| true);
rsx! {
Form { method: Method::Post,
Field {
id: "email",
label: "Email",
r#type: "email",
placeholder: "ferris@opensass.org",
helper_text: "Enter a valid email.",
required: true,
full_width: true,
handle: email,
valid_handle: email_valid,
validate_function: validate_email,
}
}
}
}
use form_rs::dioxus::{Form, Field};
use form_rs::ValidationState;
use dioxus::prelude::*;
fn validate_username(v: String) -> bool { v.len() >= 3 }
#[component]
fn AriaForm() -> Element {
let val = use_signal(String::new);
let valid = use_signal(|| true);
rsx! {
Form {
Field {
id: "username",
label: "Username",
r#type: "text",
helper_text: "3-20 characters.",
validation_state: ValidationState::Invalid("Too short".into()),
handle: val,
valid_handle: valid,
validate_function: validate_username,
}
}
}
}
use form_rs::dioxus::{Form, Group, ControlLabel};
use form_rs::LabelPlacement;
use dioxus::prelude::*;
#[component]
fn CheckboxGroup() -> Element {
rsx! {
Form {
Group {
ControlLabel {
control: rsx! { input { r#type: "checkbox" } },
label: Some(rsx! { span { "Email notifications" } }),
label_placement: LabelPlacement::End,
}
ControlLabel {
control: rsx! { input { r#type: "checkbox" } },
label: Some(rsx! { span { "SMS notifications" } }),
label_placement: LabelPlacement::End,
}
}
}
}
}
| Property | Type | Description | Default |
method | Method | HTTP submission method. | Method::Get |
action | &'static str | Form submission URL. | "" |
enc_type | EncType | Encoding type for submission. | EncType::UrlEncoded |
novalidate | bool | Bypass browser native validation. | false |
autocomplete | &'static str | autocomplete attribute. | "off" |
on_submit | Option<Callback<FormEvent>> | Submit handler. | None |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
aria_label | &'static str | Accessible label. | "" |
| Property | Type | Description | Default |
disabled | bool | Disables the control. | false |
error | bool | Shows error state. | false |
focused | bool | Shows focused state. | false |
full_width | bool | Expands to full width. | false |
required | bool | Marks as required. | false |
variant | Variant | Visual style (Outlined, Filled, Standard). | Outlined |
color | Color | Accent color. | Primary |
size | Size | Input size (Small, Medium). | Medium |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
id | &'static str | Input id and label for. Required. | - |
label | &'static str | Label text. | "" |
r#type | &'static str | Input type (text, email, passwordβ¦). | "text" |
placeholder | &'static str | Placeholder text. | "" |
helper_text | &'static str | Helper message below the input. | "" |
validation_state | ValidationState | External validation result. | None |
required | bool | HTML required attribute. | false |
disabled | bool | Disables the input. | false |
full_width | bool | Expands to full width. | true |
variant | Variant | Visual style. | Outlined |
color | Color | Accent color. | Primary |
size | Size | Input size. | Medium |
pattern | &'static str | Regex pattern for native validation. | ".*" |
maxlength | Option<usize> | Maximum character count. | None |
minlength | Option<usize> | Minimum character count. | None |
handle | Signal<String> | Controlled value signal. Required. | - |
valid_handle | Signal<bool> | Validity state signal. Required. | - |
validate_function | fn(String) -> bool | Custom validator. Required. | - |
| Property | Type | Description | Default |
html_for | &'static str | for attribute linking to input id. | "" |
error | bool | Shows error color. | false |
focused | bool | Shows focused color. | false |
required | bool | Appends required asterisk. | false |
disabled | bool | Renders in disabled style. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
error | bool | Renders in error color. | false |
valid | bool | Renders in success color. | false |
disabled | bool | Renders in disabled style. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
row | bool | Lays children horizontally. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
control | Element | The form control (checkbox, radioβ¦). Required. | - |
label | Option<Element> | Label element or text. | None |
label_placement | LabelPlacement | End, Start, Top, or Bottom. | End |
disabled | bool | Renders in disabled style. | false |
required | bool | Appends required asterisk. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
Field is a convenience composition of Control + FormLabel + Input + Helper. Use it for the common case.
- Use
Control + FormLabel + Helper manually when you need full layout control.
- Set
validation_state: ValidationState::Invalid("message".into()) to show server-side errors.
- All components are WCAG 2.2 AA compliant,
aria-describedby, aria-required, and aria-invalid are wired automatically.
You can import Form RS directly into your project to customize and modify it using the opensass cli:
os add form-rs dio
Edit Component
Adding Form RS to your project is simple:
-
Make sure your project is set up with Leptos. Follow their Getting Started Guide for setup instructions.
-
Add the Form RS component to your dependencies by including it in your Cargo.toml file:
cargo add form-rs --features=lep
-
Import the form components into your Leptos component and start using them in your app.
use form_rs::leptos::{Form, Field};
use form_rs::{Method, ValidationState};
use leptos::prelude::*;
fn validate_email(v: String) -> bool {
!v.is_empty() && v.contains('@') && v.contains('.')
}
#[component]
pub fn LoginForm() -> impl IntoView {
let email = RwSignal::new(String::new());
let email_valid = RwSignal::new(true);
view! {
<Form method=Method::Post>
<Field
id="email"
label="Email"
r#type="email"
placeholder="ferris@opensass.org"
helper_text="Enter a valid email."
required=true
full_width=true
handle=email
valid_handle=email_valid
validate_function=validate_email
/>
</Form>
}
}
use form_rs::leptos::{Form, Field};
use form_rs::ValidationState;
use leptos::prelude::*;
fn validate_username(v: String) -> bool { v.len() >= 3 }
#[component]
pub fn AriaForm() -> impl IntoView {
let val = RwSignal::new(String::new());
let valid = RwSignal::new(true);
view! {
<Form>
<Field
id="username"
label="Username"
r#type="text"
helper_text="3-20 characters."
validation_state=ValidationState::Invalid("Too short".into())
handle=val
valid_handle=valid
validate_function=validate_username
/>
</Form>
}
}
use form_rs::leptos::{Form, Group, ControlLabel};
use form_rs::LabelPlacement;
use leptos::prelude::*;
#[component]
pub fn CheckboxGroup() -> impl IntoView {
view! {
<Form>
<Group>
<ControlLabel
control=view! { <input type="checkbox" /> }.into_any()
label=view! { <span>"Email notifications"</span> }.into_any()
label_placement=LabelPlacement::End
/>
<ControlLabel
control=view! { <input type="checkbox" /> }.into_any()
label=view! { <span>"SMS notifications"</span> }.into_any()
label_placement=LabelPlacement::End
/>
</Group>
</Form>
}
}
| Property | Type | Description | Default |
method | Method | HTTP submission method. | Method::Get |
action | &'static str | Form submission URL. | "" |
enc_type | EncType | Encoding type for submission. | EncType::UrlEncoded |
novalidate | bool | Bypass browser native validation. | false |
autocomplete | &'static str | autocomplete attribute. | "off" |
on_submit | Option<Callback<SubmitEvent>> | Submit handler. | None |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
aria_label | &'static str | Accessible label. | "" |
| Property | Type | Description | Default |
disabled | bool | Disables the control. | false |
error | bool | Shows error state. | false |
focused | bool | Shows focused state. | false |
full_width | bool | Expands to full width. | false |
required | bool | Marks as required. | false |
variant | Variant | Visual style (Outlined, Filled, Standard). | Outlined |
color | Color | Accent color. | Primary |
size | Size | Input size (Small, Medium). | Medium |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
id | &'static str | Input id and label for. Required. | - |
label | &'static str | Label text. | "" |
r#type | &'static str | Input type (text, email, passwordβ¦). | "text" |
placeholder | &'static str | Placeholder text. | "" |
helper_text | &'static str | Helper message below the input. | "" |
validation_state | ValidationState | External validation result. | None |
required | bool | HTML required attribute. | false |
disabled | bool | Disables the input. | false |
full_width | bool | Expands to full width. | true |
variant | Variant | Visual style. | Outlined |
color | Color | Accent color. | Primary |
size | Size | Input size. | Medium |
pattern | &'static str | Regex pattern for native validation. | ".*" |
maxlength | usize | Maximum character count (0 = no limit). | 0 |
minlength | usize | Minimum character count. | 0 |
handle | RwSignal<String> | Controlled value signal. Required. | - |
valid_handle | RwSignal<bool> | Validity state signal. Required. | - |
validate_function | fn(String) -> bool | Custom validator. Required. | - |
| Property | Type | Description | Default |
html_for | &'static str | for attribute linking to input id. | "" |
error | bool | Shows error color. | false |
focused | bool | Shows focused color. | false |
required | bool | Appends required asterisk. | false |
disabled | bool | Renders in disabled style. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
error | bool | Renders in error color. | false |
valid | bool | Renders in success color. | false |
disabled | bool | Renders in disabled style. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
row | bool | Lays children horizontally. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
| Property | Type | Description | Default |
control | AnyView | The form control (checkbox, radioβ¦). Required. | - |
label | AnyView | Label element or text. Required. | - |
label_placement | LabelPlacement | End, Start, Top, or Bottom. | End |
disabled | bool | Renders in disabled style. | false |
required | bool | Appends required asterisk. | false |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
Field is a convenience composition of Control + FormLabel + Input + Helper. Use it for the common case.
- Use
Control + FormLabel + Helper manually when you need full layout control.
- Set
validation_state=ValidationState::Invalid("message".into()) to show server-side errors.
- All components are WCAG 2.2 AA compliant,
aria-describedby, aria-required, and aria-invalid are wired automatically.
You can import Form RS directly into your project to customize and modify it using the opensass cli:
os add form-rs lep