Skip to main content

Crate vld_leptos

Crate vld_leptos 

Source
Expand description

§vld-leptos — Leptos integration for the vld validation library

Shared validation for Leptos server functions and WASM clients. Define validation rules once, use them on both the server and the browser.

Zero dependency on leptos — works with any Leptos version (0.6, 0.7, 0.8+). Compatible with WASM and native targets.

§Key Features

FeatureDescription
validate_args!Inline validation of server function arguments
validate / [validate_with]Validate a serializable value against a schema
check_fieldSingle-field validation for reactive UI
check_all_fieldsMulti-field validation returning per-field errors
VldServerErrorSerializable error type for server→client error transport

§Quick Example

// Shared validation rules (used on server AND client)
fn name_schema() -> vld::primitives::ZString { vld::string().min(2).max(50) }
fn email_schema() -> vld::primitives::ZString { vld::string().email() }

// Server function
#[server]
async fn create_user(name: String, email: String) -> Result<(), ServerFnError> {
    vld_leptos::validate_args! {
        name  => name_schema(),
        email => email_schema(),
    }.map_err(|e| ServerFnError::new(e.to_string()))?;
    // ... create user in database
    Ok(())
}

// Client component (reactive validation)
#[component]
fn CreateUserForm() -> impl IntoView {
    let (name, set_name) = signal(String::new());
    let name_err = Memo::new(move |_| {
        vld_leptos::check_field(&name.get(), &name_schema())
    });
    // ... render form with error display
}

Modules§

prelude
Prelude — import everything you need.

Macros§

validate_args
Validate server function arguments inline.

Structs§

FieldError
A single field validation error.
VldServerError
Structured validation error for Leptos server functions.

Functions§

check_all_fields
Validate all fields of a serializable struct against a vld schema type.
check_field
Check a single value against a schema, returning an error message if invalid.
check_field_all
Check a single value, returning all error messages (not just the first).
validate
Validate a serializable value against a vld schema type.
validate_value
Validate a serde_json::Value against a vld schema type.