use cvkg_components::{Button, Checkbox, Form, FormField, Input, Select, ValidationRule};
use cvkg_core::{Never, Rect, Renderer, View};
pub struct ContactForm {
email_field: FormField<Input>,
country_field: FormField<Select<&'static str>>,
agree_field: FormField<Checkbox>,
}
impl ContactForm {
pub fn new() -> Self {
Self {
email_field: FormField::new("Email", Input::new("Enter your email"))
.required()
.rule(ValidationRule::Pattern("@".to_string())),
country_field: FormField::new(
"Country",
Select::new("Select a country")
.option("USA", "usa")
.option("Canada", "canada")
.option("UK", "uk"),
)
.required(),
agree_field: FormField::new("", Checkbox::new(false, |_| {})).required(),
}
}
}
impl View for ContactForm {
type Body = Never;
fn body(self) -> Self::Body {
unreachable!()
}
fn render(&self, _renderer: &mut dyn Renderer, _rect: Rect) {
}
}
pub struct SimpleValidatedForm {
form: Form,
}
impl SimpleValidatedForm {
pub fn new() -> Self {
let form = Form::new().submit_label("Save").on_submit(|| {
println!("Form submitted successfully!");
});
Self { form }
}
}
impl View for SimpleValidatedForm {
type Body = Never;
fn body(self) -> Self::Body {
unreachable!()
}
fn render(&self, _renderer: &mut dyn Renderer, _rect: Rect) {
}
}
fn main() {
let email = Input::new("Email address").rules(vec![
ValidationRule::Required,
ValidationRule::MinLength(5),
ValidationRule::Pattern("@".to_string()),
]);
}