Skip to main content

reinhardt_forms/
lib.rs

1//! # Reinhardt Forms
2//!
3//! Form processing and validation for the Reinhardt framework.
4//!
5//! ## Overview
6//!
7//! This crate provides comprehensive form processing capabilities inspired by Django's
8//! form system, focusing on data validation and multi-step form wizards.
9//!
10//! This crate is designed to be WASM-compatible, providing a pure form processing layer
11//! without HTML generation or platform-specific features.
12//!
13//! ## Features
14//!
15//! - **[`Form`]**: Base form class with validation
16//! - **[`ModelForm`]**: Auto-generated forms from model definitions
17//! - **[`FormSet`]**: Handle multiple forms of the same type
18//! - **[`FormWizard`]**: Multi-step form workflows
19//! - **Field Types**: 20+ field types (CharField, IntegerField, EmailField, etc.)
20//! - **WASM Support**: Compatible with WebAssembly targets via `wasm_compat` module
21//!
22//! ## Quick Start
23//!
24//! ### Basic Form
25//!
26//! ```rust,ignore
27//! use reinhardt_forms::{Form, CharField, EmailField, IntegerField};
28//!
29//! #[derive(Form)]
30//! struct ContactForm {
31//!     name: CharField,
32//!     email: EmailField,
33//!     age: IntegerField,
34//!     message: CharField,
35//! }
36//!
37//! // Validate form data
38//! let form = ContactForm::from_data(&request_data);
39//! if form.is_valid() {
40//!     let name = form.cleaned_data.name;
41//!     // Process the form...
42//! } else {
43//!     let errors = form.errors();
44//! }
45//! ```
46//!
47//! ### Model Form
48//!
49//! ```rust,ignore
50//! use reinhardt_forms::{ModelForm, ModelFormBuilder};
51//!
52//! // Auto-generate form from User model
53//! let form = ModelFormBuilder::<User>::new()
54//!     .fields(&["username", "email", "bio"])
55//!     .exclude(&["password"])
56//!     .build();
57//! ```
58//!
59//! ## Available Field Types
60//!
61//! | Field | Description |
62//! |-------|-------------|
63//! | [`CharField`] | Text input with max_length validation |
64//! | [`IntegerField`] | Integer input with min/max validation |
65//! | [`FloatField`] | Floating-point number input |
66//! | [`DecimalField`] | Decimal number with precision control |
67//! | [`BooleanField`] | Checkbox input |
68//! | [`EmailField`] | Email address validation |
69//! | [`URLField`] | URL validation |
70//! | [`DateField`] | Date input with format parsing |
71//! | [`DateTimeField`] | DateTime input |
72//! | [`TimeField`] | Time input |
73//! | [`DurationField`] | Duration input |
74//! | [`FileField`] | File upload |
75//! | [`ImageField`] | Image upload with dimension validation |
76//! | [`ChoiceField`] | Select dropdown |
77//! | [`MultipleChoiceField`] | Multi-select |
78//! | [`ModelChoiceField`] | Foreign key selection |
79//! | [`JSONField`] | JSON data input |
80//! | [`UUIDField`] | UUID input |
81//! | [`SlugField`] | URL-safe slug input |
82//! | [`RegexField`] | Custom regex validation |
83//!
84//! ## FormSets
85//!
86//! Handle multiple forms of the same type:
87//!
88//! ```rust,ignore
89//! use reinhardt_forms::{FormSet, FormSetFactory};
90//!
91//! // Create a formset with 3 forms
92//! let formset = FormSetFactory::<ItemForm>::new()
93//!     .extra(3)
94//!     .min_num(1)
95//!     .max_num(10)
96//!     .build();
97//!
98//! if formset.is_valid() {
99//!     for form in formset.forms() {
100//!         // Process each form
101//!     }
102//! }
103//! ```
104//!
105//! ## Form Wizard
106//!
107//! Multi-step forms:
108//!
109//! ```rust,ignore
110//! use reinhardt_forms::{FormWizard, WizardStep};
111//!
112//! let wizard = FormWizard::new()
113//!     .add_step(WizardStep::new("account", AccountForm::new()))
114//!     .add_step(WizardStep::new("profile", ProfileForm::new()))
115//!     .add_step(WizardStep::new("confirmation", ConfirmForm::new()));
116//!
117//! // Process wizard step
118//! let result = wizard.process_step(&request).await?;
119//! ```
120
121pub mod bound_field;
122pub mod field;
123pub mod fields;
124pub mod form;
125pub mod formset;
126pub mod formsets;
127pub mod model_form;
128pub mod model_formset;
129pub mod validators;
130pub mod wasm_compat;
131pub mod wizard;
132
133pub use bound_field::BoundField;
134pub use field::{
135	ErrorType,
136	FieldError,
137	FieldResult,
138	FormField as Field, // Alias for compatibility
139	FormField,
140	Widget,
141	escape_attribute,
142	html_escape,
143};
144pub use fields::{
145	BooleanField, CharField, ChoiceField, ColorField, ComboField, DateField, DateTimeField,
146	DecimalField, DurationField, EmailField, FileField, FloatField, GenericIPAddressField,
147	IPProtocol, ImageField, IntegerField, JSONField, ModelChoiceField, ModelMultipleChoiceField,
148	MultiValueField, MultipleChoiceField, PASSWORD_REDACTED, PasswordField, RegexField, SlugField,
149	SplitDateTimeField, TimeField, URLField, UUIDField,
150};
151pub use form::{Form, FormError, FormResult};
152pub use formset::FormSet;
153pub use formsets::{
154	FormSetFactory,
155	InlineFormSet,
156	ModelFormSet as AdvancedModelFormSet, // Renamed to avoid conflict
157};
158pub use model_form::{FieldType, FormModel, ModelForm, ModelFormBuilder, ModelFormConfig};
159pub use model_formset::{ModelFormSet, ModelFormSetBuilder, ModelFormSetConfig};
160pub use validators::{SlugValidator, UrlValidator};
161pub use wizard::{FormWizard, WizardStep};