vld-dioxus
Dioxus integration for the vld validation library.
Define validation rules once — use them on both server and client (WASM).
No direct dependency on dioxus — works with any Dioxus version (0.5, 0.6, 0.7+) and compiles for WASM targets.
Installation
[]
= "0.1"
= "0.1"
= "0.7" # or your version
Quick Start
1. Shared Validation Schemas
Define schema factories in a shared module compiled for both server and WASM:
// shared.rs
2. Server Function Validation
Use validate_args! inside #[server] functions:
use *;
async
3. Client-Side Reactive Validation
Use check_field inside Dioxus use_memo hooks for instant feedback:
4. Server -> Client Error Display
Parse structured errors from server function responses:
API Reference
Error Types
| Type | Description |
|---|---|
VldServerError |
Structured error with per-field messages, serializable for transport |
FieldError |
Single field error: { field, message } |
VldServerError Methods
| Method | Returns | Description |
|---|---|---|
validation(fields) |
VldServerError |
Create from a list of FieldError |
internal(msg) |
VldServerError |
Create an internal error |
field_error(name) |
Option<&str> |
First error message for a field |
field_errors(name) |
Vec<&str> |
All error messages for a field |
has_field_error(name) |
bool |
Check if a field has errors |
error_fields() |
Vec<&str> |
All field names with errors |
from_json(s) |
Option<Self> |
Parse from JSON string |
to_string() |
String |
Serialize to JSON (via Display) |
Validation Functions
| Function | Use Case |
|---|---|
validate::<Schema, T>(data) |
Validate a Serialize struct against a vld::schema! type |
validate_value::<Schema>(json) |
Validate a serde_json::Value directly |
check_field(value, schema) |
Single-field check -> Option<String> error |
check_field_all(value, schema) |
Single-field check -> Vec<String> all errors |
check_all_fields::<Schema, T>(data) |
Multi-field check -> Vec<FieldError> |
Macros
| Macro | Description |
|---|---|
validate_args! { field => schema, ... } |
Inline validation of server function arguments |
Custom Error Type
For advanced use cases, wrap VldServerError in your own error enum:
use ;
// Implement FromServerFnError for AppError...
async
Running the Example
License
MIT