Struct InputProps

Source
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>,
}
Available on crate feature 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 String as input and returns a bool.

ยง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.
  • 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">).
  • formenctype: [&'static str]
    • Form data set encoding type for submission (for <input r#type="image" | "submit">).
  • formmethod: [&'static str]
    • HTTP method to use for form submission (for <input r#type="image" | "submit">).
  • formnovalidate: bool
    • Bypass form validation for submission (for <input r#type="image" | "submit">).
  • formtarget: [&'static str]
    • Browsing context for form submission (for <input r#type="image" | "submit">).
  • height: Option<u32>
    • Same as the height attribute for <img> elements.
  • list: [&'static str]
    • ID of the <datalist> element to use for autocomplete suggestions.
  • 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">.
  • 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 width attribute for <img> elements.

Fieldsยง

ยง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.

ยง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 String as input and returns a bool.

ยง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.

ยง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">).

ยงformenctype: &'static str

Form data set encoding type for submission (for <input r#type="image" | "submit">).

ยงformmethod: &'static str

HTTP method to use for form submission (for <input r#type="image" | "submit">).

ยงformnovalidate: bool

Bypass form validation for submission (for <input r#type="image" | "submit">).

ยงformtarget: &'static str

Browsing context for form submission (for <input r#type="image" | "submit">).

ยงheight: Option<u32>

Same as the height attribute for <img> elements.

ยงlist: &'static str

ID of the <datalist> element to use for autocomplete suggestions.

ยง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">.

ยง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 width attribute for <img> elements.

Implementationsยง

Sourceยง

impl InputProps

Source

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ยง

Sourceยง

impl Props for InputProps

Sourceยง

type Builder = InputPropsBuilder

Sourceยง

fn builder() -> Self::Builder

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> InitializeFromFunction<T> for T

Sourceยง

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Sourceยง

impl<T> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Sourceยง

impl<T> IntoPropValue<Option<T>> for T

Sourceยง

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Sourceยง

impl<T> IntoPropValue<T> for T

Sourceยง

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
Sourceยง

impl<T> Same for T

Sourceยง

type Output = T

Should always be Self
Sourceยง

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Sourceยง

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Sourceยง

impl<T> StorageAccess<T> for T

Sourceยง

fn as_borrowed(&self) -> &T

Borrows the value.
Sourceยง

fn into_taken(self) -> T

Takes the value.
Sourceยง

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Sourceยง

fn super_from(input: T) -> O

Convert from a type to another type.
Sourceยง

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Sourceยง

fn super_into(self) -> O

Convert from a type to another type.
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V

Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

Sourceยง

impl<T> ErasedDestructor for T
where T: 'static,

Sourceยง

impl<T> HasAllProps<(), T> for T

Sourceยง

impl<T> MaybeSendSync for T