pub struct InputProps {Show 50 fields
pub type: &'static str,
pub label: &'static str,
pub name: &'static str,
pub required: bool,
pub error_message: &'static str,
pub input_class: &'static str,
pub field_class: &'static str,
pub label_class: &'static str,
pub class: &'static str,
pub error_class: &'static str,
pub icon_class: &'static str,
pub handle: (ReadSignal<String>, WriteSignal<String>),
pub valid_handle: (ReadSignal<bool>, WriteSignal<bool>),
pub validate_function: fn(String) -> bool,
pub eye_active: &'static str,
pub eye_disabled: &'static str,
pub id: &'static str,
pub placeholder: &'static str,
pub aria_label: &'static str,
pub aria_required: &'static str,
pub aria_invalid: &'static str,
pub aria_describedby: &'static str,
pub accept: &'static str,
pub alt: &'static str,
pub autocapitalize: &'static str,
pub autocomplete: &'static str,
pub capture: &'static str,
pub checked: bool,
pub dirname: &'static str,
pub disabled: bool,
pub form: &'static str,
pub formaction: &'static str,
pub formenctype: &'static str,
pub formmethod: &'static str,
pub formnovalidate: bool,
pub formtarget: &'static str,
pub height: Option<u32>,
pub list: &'static str,
pub max: &'static str,
pub maxlength: Option<usize>,
pub min: &'static str,
pub minlength: Option<usize>,
pub multiple: bool,
pub pattern: &'static str,
pub readonly: bool,
pub size: Option<u32>,
pub src: &'static str,
pub step: &'static str,
pub value: &'static str,
pub width: Option<u32>,
}lep only.Expand description
Props for the Input component.
A custom input component that handles user input and validation.
ยงArguments
props- The properties of the component.valid_handle- A state hook to track the validity of the input.aria_invalid- A string representing the โaria-invalidโ attribute value for accessibility. Defaults to โtrueโ.aria_required- A string representing the โaria-requiredโ attribute value for accessibility. Defaults to โtrueโ.r#type- The type of the input element. Defaults to โtextโ.handle- A state hook to set the value of the input.validate_function- A function to validate the input value.
ยงReturns
(IntoView): A Leptos element representation of the input component.
ยงExamples
use leptos::{prelude::*, *};
use regex::Regex;
use serde::{Deserialize, Serialize};
use input_rs::leptos::Input;
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
struct LoginUserSchema {
email: String,
password: String,
}
fn validate_email(email: String) -> bool {
let pattern = Regex::new(r"^[^ ]+@[^ ]+\.[a-z]{2,3}$").unwrap();
pattern.is_match(&email)
}
fn validate_password(password: String) -> bool {
!&password.is_empty()
}
#[component]
fn LoginForm() -> impl IntoView {
let error_handle = signal(String::default());
let error = error_handle.0.get();
let email_valid_handle = signal(true);
let email_valid = email_valid_handle.0.get();
let password_valid_handle = signal(true);
let password_valid = password_valid_handle.0.get();
let email_handle = signal(String::default());
let email = email_handle.0.get();
let password_handle = signal(String::default());
let password = password_handle.0.get();
let onsubmit = move |ev: leptos::ev::SubmitEvent| {
ev.prevent_default();
let email_ref = email.clone();
let password_ref = password.clone();
let error_handle = error_handle.clone();
// Custom logic for your endpoint goes here
};
view! {
<div class="form-one-content" role="main" aria-label="Sign In Form">
<div class="text">
<h2>{"Sign In"}</h2>
{ move || if !error.is_empty() {
Some(view! {<div class="error">error</div>})
}
else {None}
}
</div>
<form on:submit={onsubmit}>
<Input
r#type="text"
handle={email_handle}
name="email"
label="Email"
placeholder="Email"
input_class="form-one-field"
field_class="form-one-field"
error_class="error-txt"
required=true
valid_handle={email_valid_handle}
validate_function={validate_email}
error_message="Enter a valid email address"
/>
<Input
r#type="password"
handle={password_handle}
name="password"
label="Password"
placeholder="Password"
input_class="form-one-field"
field_class="form-one-field"
error_class="error-txt"
required=true
valid_handle={password_valid_handle}
validate_function={validate_password}
error_message="Password can't be blank!"
eye_active="fa fa-eye"
eye_disabled="fa fa-eye-slash"
/>
<div class="form-one-forgot-pass">
<a href="#">{"Forgot Password?"}</a>
</div>
<button type="submit">{"Sign in"}</button>
<div class="sign-up">
{"Not a member?"}
<a href="#">{"Sign up now"}</a>
</div>
</form>
</div>
}
}ยงRequired Props
- handle: [
(ReadSignal<String>, WriteSignal<String>)]- The state handle for managing the value of the input.
- valid_handle: [
(ReadSignal<bool>, WriteSignal<bool>)]- The state handle for managing the validity state of the input.
- validate_function: [
fn(String) -> bool]- A callback function to validate the input value. It takes a
Stringas input and returns abool.
- A callback function to validate the input value. It takes a
ยงOptional Props
- r#type: [
&'static str]-
Props for a custom input component. This struct includes all possible attributes for an HTML
<input>element. See MDN docs for more details.The type of the input, e.g., โtextโ, โpasswordโ, etc.
-
- label: [
&'static str]- The label to be displayed for the input field.
- name: [
&'static str]- The name of the input field, used for form submission and accessibility.
- required:
bool- Indicates whether the input is required or not.
- error_message: [
&'static str]- The error message to display when there is a validation error.
- input_class: [
&'static str]- The CSS class to be applied to all inner elements.
- field_class: [
&'static str]- The CSS class to be applied to the inner input element and icon.
- label_class: [
&'static str]- The CSS class to be applied to the label for the input element.
- class: [
&'static str]- The CSS class to be applied to the input element.
- error_class: [
&'static str]- The CSS class to be applied to the error div element.
- icon_class: [
&'static str]- The CSS class to be applied to the icon element.
- eye_active: [
&'static str]- The icon when the password is visible. Assuming fontawesome icons are used by default.
- eye_disabled: [
&'static str]- The icon when the password is not visible. Assuming fontawesome icons are used by default.
- id: [
&'static str]- The ID attribute of the input element.
- placeholder: [
&'static str]- The placeholder text to be displayed in the input element.
- aria_label: [
&'static str]- The aria-label attribute for screen readers, providing a label for accessibility.
- aria_required: [
&'static str]- The aria-required attribute for screen readers, indicating whether the input is required.
- aria_invalid: [
&'static str]- The aria-invalid attribute for screen readers, indicating whether the input value is invalid.
- aria_describedby: [
&'static str]- The aria-describedby attribute for screen readers, describing the input elementโs error message.
- accept: [
&'static str]- Hint for expected file type in file upload controls.
- alt: [
&'static str]- The alternative text for
<input r#type="image">. Required for accessibility.
- The alternative text for
- autocapitalize: [
&'static str]- Controls automatic capitalization in inputted text.
- autocomplete: [
&'static str]- Hint for the browserโs autofill feature.
- capture: [
&'static str]- Media capture input method in file upload controls.
- checked:
bool- Whether the control is checked (for checkboxes or radio buttons).
- dirname: [
&'static str]- Name of the form field to use for sending the elementโs directionality in form submission.
- disabled:
bool- Whether the form control is disabled.
- form: [
&'static str]- Associates the input with a specific form element.
- formaction: [
&'static str]- URL to use for form submission (for
<input r#type="image" | "submit">).
- URL to use for form submission (for
- formenctype: [
&'static str]- Form data set encoding type for submission (for
<input r#type="image" | "submit">).
- Form data set encoding type for submission (for
- formmethod: [
&'static str]- HTTP method to use for form submission (for
<input r#type="image" | "submit">).
- HTTP method to use for form submission (for
- formnovalidate:
bool- Bypass form validation for submission (for
<input r#type="image" | "submit">).
- Bypass form validation for submission (for
- formtarget: [
&'static str]- Browsing context for form submission (for
<input r#type="image" | "submit">).
- Browsing context for form submission (for
- height:
Option<u32>- Same as the
heightattribute for<img>elements.
- Same as the
- list: [
&'static str]- ID of the
<datalist>element to use for autocomplete suggestions.
- ID of the
- max: [
&'static str]- The maximum value for date, number, range, etc.
- maxlength:
Option<usize>- Maximum length of the input value (in characters).
- min: [
&'static str]- The minimum value for date, number, range, etc.
- minlength:
Option<usize>- Minimum length of the input value (in characters).
- multiple:
bool- Boolean indicating whether multiple values are allowed (for file inputs, emails, etc.).
- pattern: [
&'static str]- Regex pattern the value must match to be valid.
- readonly:
bool- Boolean indicating whether the input is read-only.
- size:
Option<u32>- Size of the input field (e.g., character width).
- src: [
&'static str]- Address of the image resource for
<input r#type="image">.
- Address of the image resource for
- step: [
&'static str]- Incremental values that are valid for the input.
- value: [
&'static str]- The value of the control (used for two-way data binding).
- width:
Option<u32>- Same as the
widthattribute for<img>elements.
- Same as the
Fieldsยง
ยงtype: &'static strProps for a custom input component.
This struct includes all possible attributes for an HTML <input> element.
See MDN docs for more details.
The type of the input, e.g., โtextโ, โpasswordโ, etc.
label: &'static strThe label to be displayed for the input field.
name: &'static strThe name of the input field, used for form submission and accessibility.
required: boolIndicates whether the input is required or not.
error_message: &'static strThe error message to display when there is a validation error.
input_class: &'static strThe CSS class to be applied to all inner elements.
field_class: &'static strThe CSS class to be applied to the inner input element and icon.
label_class: &'static strThe CSS class to be applied to the label for the input element.
class: &'static strThe CSS class to be applied to the input element.
error_class: &'static strThe CSS class to be applied to the error div element.
icon_class: &'static strThe CSS class to be applied to the icon element.
handle: (ReadSignal<String>, WriteSignal<String>)The state handle for managing the value of the input.
valid_handle: (ReadSignal<bool>, WriteSignal<bool>)The state handle for managing the validity state of the input.
validate_function: fn(String) -> boolA callback function to validate the input value. It takes a String as input and returns a bool.
eye_active: &'static strThe icon when the password is visible. Assuming fontawesome icons are used by default.
eye_disabled: &'static strThe icon when the password is not visible. Assuming fontawesome icons are used by default.
id: &'static strThe ID attribute of the input element.
placeholder: &'static strThe placeholder text to be displayed in the input element.
aria_label: &'static strThe aria-label attribute for screen readers, providing a label for accessibility.
aria_required: &'static strThe aria-required attribute for screen readers, indicating whether the input is required.
aria_invalid: &'static strThe aria-invalid attribute for screen readers, indicating whether the input value is invalid.
aria_describedby: &'static strThe aria-describedby attribute for screen readers, describing the input elementโs error message.
accept: &'static strHint for expected file type in file upload controls.
alt: &'static strThe alternative text for <input r#type="image">. Required for accessibility.
autocapitalize: &'static strControls automatic capitalization in inputted text.
autocomplete: &'static strHint for the browserโs autofill feature.
capture: &'static strMedia capture input method in file upload controls.
checked: boolWhether the control is checked (for checkboxes or radio buttons).
dirname: &'static strName of the form field to use for sending the elementโs directionality in form submission.
disabled: boolWhether the form control is disabled.
form: &'static strAssociates the input with a specific form element.
formaction: &'static strURL to use for form submission (for <input r#type="image" | "submit">).
formenctype: &'static strForm data set encoding type for submission (for <input r#type="image" | "submit">).
formmethod: &'static strHTTP method to use for form submission (for <input r#type="image" | "submit">).
formnovalidate: boolBypass form validation for submission (for <input r#type="image" | "submit">).
formtarget: &'static strBrowsing context for form submission (for <input r#type="image" | "submit">).
height: Option<u32>Same as the height attribute for <img> elements.
list: &'static strID of the <datalist> element to use for autocomplete suggestions.
max: &'static strThe maximum value for date, number, range, etc.
maxlength: Option<usize>Maximum length of the input value (in characters).
min: &'static strThe minimum value for date, number, range, etc.
minlength: Option<usize>Minimum length of the input value (in characters).
multiple: boolBoolean indicating whether multiple values are allowed (for file inputs, emails, etc.).
pattern: &'static strRegex pattern the value must match to be valid.
readonly: boolBoolean indicating whether the input is read-only.
size: Option<u32>Size of the input field (e.g., character width).
src: &'static strAddress of the image resource for <input r#type="image">.
step: &'static strIncremental values that are valid for the input.
value: &'static strThe value of the control (used for two-way data binding).
width: Option<u32>Same as the width attribute for <img> elements.
Implementationsยง
Sourceยงimpl InputProps
impl InputProps
Sourcepub fn builder() -> InputPropsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>
pub fn builder() -> InputPropsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>
Create a builder for building InputProps.
On the builder, call .r#type(...)(optional), .label(...)(optional), .name(...)(optional), .required(...)(optional), .error_message(...)(optional), .input_class(...)(optional), .field_class(...)(optional), .label_class(...)(optional), .class(...)(optional), .error_class(...)(optional), .icon_class(...)(optional), .handle(...), .valid_handle(...), .validate_function(...), .eye_active(...)(optional), .eye_disabled(...)(optional), .id(...)(optional), .placeholder(...)(optional), .aria_label(...)(optional), .aria_required(...)(optional), .aria_invalid(...)(optional), .aria_describedby(...)(optional), .accept(...)(optional), .alt(...)(optional), .autocapitalize(...)(optional), .autocomplete(...)(optional), .capture(...)(optional), .checked(...)(optional), .dirname(...)(optional), .disabled(...)(optional), .form(...)(optional), .formaction(...)(optional), .formenctype(...)(optional), .formmethod(...)(optional), .formnovalidate(...)(optional), .formtarget(...)(optional), .height(...)(optional), .list(...)(optional), .max(...)(optional), .maxlength(...)(optional), .min(...)(optional), .minlength(...)(optional), .multiple(...)(optional), .pattern(...)(optional), .readonly(...)(optional), .size(...)(optional), .src(...)(optional), .step(...)(optional), .value(...)(optional), .width(...)(optional) to set the values of the fields.
Finally, call .build() to create the instance of InputProps.
Trait Implementationsยง
Auto Trait Implementationsยง
impl Freeze for InputProps
impl RefUnwindSafe for InputProps
impl Send for InputProps
impl Sync for InputProps
impl Unpin for InputProps
impl UnwindSafe for InputProps
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Sourceยงfn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
Sourceยงfn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Sourceยงfn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงimpl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Sourceยงfn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Sourceยงimpl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Sourceยงfn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.