Incular logoIncular
API ReferenceInput & Forms

Form

Validation registry with register, validate, save, and observation.

Controller-oriented validation — clones are stable identity, no GlobalKey needed. Form is a non-visual registry (FormState/FormController aliases).

MethodEffect
new() / of_child(w)Empty registry, optional child
register(controller)Bind a controller, returns FormField
register_with_restorationBind with persistence scope + key
validate()Visit live fields, prune unmounted, returns bool
reset()Restore initial text, clear errors
save() / submit()Validate then run submit callbacks
errors() / field_count()Inspection
observe / add_listenerReact to validation changes
use incular::prelude::*;
use incular::controls_prelude::TextField;

fn main() {
    let controller = TextEditingController::with_text("");
    let form = Form::new();
    let _ = form
        .register(controller.clone())
        .validator(|text| {
            if text.is_empty() {
                Some("Required".to_string())
            } else {
                None
            }
        })
        .on_submit(|value| println!("submitted: {value}"));
    println!("valid: {}", form.validate());
    let app = Application::new(move |_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(TextField::new(controller.clone()).placeholder("Name"))
            .build()
            .into()
    })
    .expect("valid application");
    incular::run(app).expect("run application");
}

AutovalidateMode: Disabled (default) / OnUserInteraction / Always.

Related: FormField, Input Formatters.